From 5a3560fc12216db0aeef2bb4d61611ab48cf38f1 Mon Sep 17 00:00:00 2001 From: bniwredyc Date: Mon, 27 Mar 2023 16:45:07 +0200 Subject: [PATCH] shout create --- src/components/Views/Create.tsx | 15 ++++++++++++++- src/graphql/mutation/article-create.ts | 4 ++-- src/stores/router.ts | 2 +- src/utils/apiClient.ts | 7 ++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/components/Views/Create.tsx b/src/components/Views/Create.tsx index 40511d6c..045cdfd8 100644 --- a/src/components/Views/Create.tsx +++ b/src/components/Views/Create.tsx @@ -47,8 +47,21 @@ export const CreateView = () => { setTopics(allTopics) }) - const handleFormSubmit = (e) => { + const handleFormSubmit = async (e) => { e.preventDefault() + + const newShout = await apiClient.createArticle({ + article: { + slug: form.slug, + title: form.title, + subtitle: form.subtitle, + body: form.body, + topics: form.selectedTopics.map((topic) => topic.slug), + mainTopic: form.selectedTopics[0].slug + } + }) + + router.open(getPagePath(router, 'article', { slug: newShout.slug })) } const handleTitleInputChange = (e) => { diff --git a/src/graphql/mutation/article-create.ts b/src/graphql/mutation/article-create.ts index b72bad98..90ad3e7e 100644 --- a/src/graphql/mutation/article-create.ts +++ b/src/graphql/mutation/article-create.ts @@ -5,13 +5,13 @@ export default gql` createShout(inp: $shout) { error shout { - _id: slug + id slug title subtitle body topics { - # id + id title slug } diff --git a/src/stores/router.ts b/src/stores/router.ts index fbf26b34..2904b23a 100644 --- a/src/stores/router.ts +++ b/src/stores/router.ts @@ -67,7 +67,7 @@ const handleClientRouteLinkClick = (event) => { } const anchor = document.querySelector(selector) - const headerOffset = 80 // 100px for header + const headerOffset = 80 // 80px for header const elementPosition = anchor ? anchor.getBoundingClientRect().top : 0 const newScrollTop = elementPosition + window.scrollY - headerOffset diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index e5bdf81a..c4fa2880 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -14,7 +14,8 @@ import type { ProfileInput, ReactionInput, Chat, - ReactionBy + ReactionBy, + Shout } from '../graphql/types.gen' import { publicGraphQLClient } from '../graphql/publicGraphQLClient' import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient' @@ -234,10 +235,10 @@ export const apiClient = { const response = await publicGraphQLClient.query(topicBySlug, { slug }).toPromise() return response.data.getTopic }, - createArticle: async ({ article }: { article: ShoutInput }) => { + createArticle: async ({ article }: { article: ShoutInput }): Promise => { const response = await privateGraphQLClient.mutation(createArticle, { shout: article }).toPromise() console.debug('[createArticle]:', response.data) - return response.data.createShout + return response.data.createShout.shout }, createReaction: async (input: ReactionInput) => { const response = await privateGraphQLClient.mutation(reactionCreate, { reaction: input }).toPromise()