From c7e9acd9483ecfab57766b3e8cf71f289b85127e Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Tue, 4 Oct 2022 10:41:09 +0300 Subject: [PATCH] feat: tag project api, reactive story updating --- api/functions/graphql/types/post.js | 14 ++++++++++++-- .../Components/StoryForm/StoryForm.tsx | 4 ++-- .../Components/StoryForm/createStory.graphql | 6 ++++++ .../CreateStoryPage/CreateStoryPage.tsx | 2 ++ src/graphql/index.tsx | 8 +++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/api/functions/graphql/types/post.js b/api/functions/graphql/types/post.js index f899854..d6a5021 100644 --- a/api/functions/graphql/types/post.js +++ b/api/functions/graphql/types/post.js @@ -117,7 +117,7 @@ const Story = objectType({ t.field('project', { type: "Project", resolve(parent) { - return null + return prisma.story.findUnique({ where: { id: parent.id } }).project(); } }) @@ -429,7 +429,7 @@ const createStory = extendType({ type: 'Story', args: { data: StoryInputType }, async resolve(_root, args, ctx) { - const { id, title, body, cover_image, tags, is_published } = args.data; + const { id, title, body, project_id, cover_image, tags, is_published } = args.data; const user = await getUserByPubKey(ctx.userPubKey); // Do some validation @@ -536,6 +536,11 @@ const createStory = extendType({ cover_image: '', excerpt, is_published: was_published || is_published, + project: { + connect: { + id: project_id, + } + }, tags: { connectOrCreate: tags.map(tag => { @@ -581,6 +586,11 @@ const createStory = extendType({ } }) }, + project: { + connect: { + id: project_id, + } + }, user: { connect: { id: user.id, diff --git a/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.tsx b/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.tsx index bc0c439..8c83dcd 100644 --- a/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.tsx +++ b/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.tsx @@ -203,8 +203,8 @@ export default function StoryForm(props: Props) { disabled={loading} > {props.isUpdating ? - "Update" : - "Publish" + (loading ? "Updating..." : "Update") : + (loading ? "Publishing..." : "Publish") } {!props.isPublished && diff --git a/src/features/Posts/pages/CreatePostPage/Components/StoryForm/createStory.graphql b/src/features/Posts/pages/CreatePostPage/Components/StoryForm/createStory.graphql index 5216670..41b5d8f 100644 --- a/src/features/Posts/pages/CreatePostPage/Components/StoryForm/createStory.graphql +++ b/src/features/Posts/pages/CreatePostPage/Components/StoryForm/createStory.graphql @@ -12,6 +12,12 @@ mutation createStory($data: StoryInputType) { is_published type cover_image + project { + id + title + hashtag + thumbnail_image + } # comments_count } } diff --git a/src/features/Posts/pages/CreatePostPage/CreateStoryPage/CreateStoryPage.tsx b/src/features/Posts/pages/CreatePostPage/CreateStoryPage/CreateStoryPage.tsx index 765cad1..2665d53 100644 --- a/src/features/Posts/pages/CreatePostPage/CreateStoryPage/CreateStoryPage.tsx +++ b/src/features/Posts/pages/CreatePostPage/CreateStoryPage/CreateStoryPage.tsx @@ -56,6 +56,7 @@ function CreateStoryPage() { story: state.staging.story || storageService.get() })) + const formMethods = useForm({ resolver: yupResolver(schema) as Resolver, shouldFocusError: false, @@ -66,6 +67,7 @@ function CreateStoryPage() { tags: story?.tags ?? [], body: story?.body ?? '', is_published: story?.is_published ?? false, + project: story?.project, }, }); diff --git a/src/graphql/index.tsx b/src/graphql/index.tsx index e2770dd..f851551 100644 --- a/src/graphql/index.tsx +++ b/src/graphql/index.tsx @@ -933,7 +933,7 @@ export type CreateStoryMutationVariables = Exact<{ }>; -export type CreateStoryMutation = { __typename?: 'Mutation', createStory: { __typename?: 'Story', id: number, title: string, createdAt: any, body: string, votes_count: number, is_published: boolean | null, type: string, cover_image: string | null, tags: Array<{ __typename?: 'Tag', id: number, title: string }> } | null }; +export type CreateStoryMutation = { __typename?: 'Mutation', createStory: { __typename?: 'Story', id: number, title: string, createdAt: any, body: string, votes_count: number, is_published: boolean | null, type: string, cover_image: string | null, tags: Array<{ __typename?: 'Tag', id: number, title: string }>, project: { __typename?: 'Project', id: number, title: string, hashtag: string, thumbnail_image: string } | null } | null }; export type DeleteStoryMutationVariables = Exact<{ deleteStoryId: Scalars['Int']; @@ -1722,6 +1722,12 @@ export const CreateStoryDocument = gql` is_published type cover_image + project { + id + title + hashtag + thumbnail_image + } } } `;