From 3fadd719b2ce62838917af6301c1de4829186c53 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 6 May 2024 19:17:34 +0300 Subject: [PATCH 1/4] load-after-create --- src/components/Article/CommentsTree.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 60054831..8ed6fae2 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -29,7 +29,7 @@ export const CommentsTree = (props: Props) => { const [newReactions, setNewReactions] = createSignal([]) const [clearEditor, setClearEditor] = createSignal(false) const [clickedReplyId, setClickedReplyId] = createSignal() - const { reactionEntities, createReaction } = useReactions() + const { reactionEntities, createReaction, loadReactionsBy } = useReactions() const comments = createMemo(() => Object.values(reactionEntities).filter((reaction) => reaction.kind === 'COMMENT'), @@ -76,6 +76,7 @@ export const CommentsTree = (props: Props) => { shout: props.shoutId, }) setClearEditor(true) + await loadReactionsBy({ by: { shout: props.shoutSlug } }) } catch (error) { console.error('[handleCreate reaction]:', error) } From 3ce53728ea49598acd6772eac4937f33564c7663 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 6 May 2024 21:16:13 +0300 Subject: [PATCH 2/4] drafts-reload-session --- .../Views/DraftsView/DraftsView.tsx | 18 +++--- src/graphql/client/core.ts | 2 +- .../query/core/articles-load-drafts.ts | 61 ++++++++++--------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/components/Views/DraftsView/DraftsView.tsx b/src/components/Views/DraftsView/DraftsView.tsx index acbc30db..957f7ffe 100644 --- a/src/components/Views/DraftsView/DraftsView.tsx +++ b/src/components/Views/DraftsView/DraftsView.tsx @@ -13,16 +13,20 @@ import { Loading } from '../../_shared/Loading' import styles from './DraftsView.module.scss' export const DraftsView = () => { - const { session } = useSession() + const { author, loadSession } = useSession() const [drafts, setDrafts] = createSignal([]) createEffect( on( - () => session(), - async (s) => { - if (s) { - const loadedDrafts = await apiClient.getDrafts() - setDrafts(loadedDrafts.reverse() || []) + () => author(), + async (a) => { + if (a) { + const { shouts: loadedDrafts, error } = await apiClient.getDrafts() + if (error) { + console.warn(error) + await loadSession() + } + setDrafts(loadedDrafts || []) } }, ), @@ -46,7 +50,7 @@ export const DraftsView = () => { return (
- }> + }>
diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index e80f2e6d..9c083e86 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -175,7 +175,7 @@ export const apiClient = { console.debug('[graphql.client.core] deleteShout:', response) }, - getDrafts: async (): Promise => { + getDrafts: async (): Promise => { const response = await apiClient.private.query(draftsLoad, {}).toPromise() console.debug('[graphql.client.core] getDrafts:', response) return response.data.get_shouts_drafts diff --git a/src/graphql/query/core/articles-load-drafts.ts b/src/graphql/query/core/articles-load-drafts.ts index f81d0a2f..136a14bf 100644 --- a/src/graphql/query/core/articles-load-drafts.ts +++ b/src/graphql/query/core/articles-load-drafts.ts @@ -3,40 +3,43 @@ import { gql } from '@urql/core' export default gql` query LoadDraftsQuery { get_shouts_drafts { - id - title - subtitle - slug - layout - cover - # community - media - main_topic - topics { + error + shouts { id title - body + subtitle slug - stat { - shouts - authors - followers + layout + cover + # community + media + main_topic + topics { + id + title + body + slug + stat { + shouts + authors + followers + } + } + authors { + id + name + slug + pic + created_at } - } - authors { - id - name - slug - pic created_at - } - created_at - published_at - featured_at - stat { - viewed - rating - commented + published_at + featured_at + stat { + viewed + rating + commented + } } } } From dcbeb55ac9710d31fd01abc107a5161eb561b1b9 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 6 May 2024 21:37:54 +0300 Subject: [PATCH 3/4] draft-permission-error-msg --- public/locales/en/translation.json | 1 + public/locales/ru/translation.json | 1 + src/pages/edit.page.tsx | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 2690613b..267804e7 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -448,6 +448,7 @@ "Write your colleagues name or email": "Write your colleague's name or email", "You can download multiple tracks at once in .mp3, .wav or .flac formats": "You can download multiple tracks at once in .mp3, .wav or .flac formats", "You can now login using your new password": "Теперь вы можете входить с помощью нового пароля", + "You can't edit this post": "You can't edit this post", "You were successfully authorized": "You were successfully authorized", "You ll be able to participate in discussions, rate others' comments and learn about new responses": "You ll be able to participate in discussions, rate others' comments and learn about new responses", "You've confirmed email": "You've confirmed email", diff --git a/public/locales/ru/translation.json b/public/locales/ru/translation.json index 2dc94b46..30e38a8d 100644 --- a/public/locales/ru/translation.json +++ b/public/locales/ru/translation.json @@ -471,6 +471,7 @@ "You can download multiple tracks at once in .mp3, .wav or .flac formats": "Можно загрузить сразу несколько треков в форматах .mp3, .wav или .flac", "You can now login using your new password": "Теперь вы можете входить с помощью нового пароля", "You was successfully authorized": "Вы были успешно авторизованы", + "You can't edit this post": "Вы не можете редактировать этот материал", "You ll be able to participate in discussions, rate others' comments and learn about new responses": "Вы сможете участвовать в обсуждениях, оценивать комментарии других и узнавать о новых ответах", "You've confirmed email": "Вы подтвердили почту", "You've reached a non-existed page": "Вы попали на несуществующую страницу", diff --git a/src/pages/edit.page.tsx b/src/pages/edit.page.tsx index 6b33a92f..21353681 100644 --- a/src/pages/edit.page.tsx +++ b/src/pages/edit.page.tsx @@ -37,7 +37,8 @@ export const EditPage = () => { const fail = async (error: string) => { console.error(error) - await snackbar?.showSnackbar({ type: 'error', body: t(error) }) + const errorMessage = error === 'forbidden' ? "You can't edit this post" : error + await snackbar?.showSnackbar({ type: 'error', body: t(errorMessage) }) redirectPage(router, 'drafts') } From 502dcfae6df8f70a0ae776ba69831a26d70f0cf3 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 6 May 2024 21:45:17 +0300 Subject: [PATCH 4/4] is-posting-comment-feature --- src/components/Article/CommentsTree.tsx | 4 ++++ src/components/Editor/SimplifiedEditor.tsx | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 8ed6fae2..e8acc1fa 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -68,7 +68,9 @@ export const CommentsTree = (props: Props) => { setCookie() } }) + const [posting, setPosting] = createSignal(false) const handleSubmitComment = async (value: string) => { + setPosting(true) try { await createReaction({ kind: ReactionKind.Comment, @@ -81,6 +83,7 @@ export const CommentsTree = (props: Props) => { console.error('[handleCreate reaction]:', error) } setClearEditor(false) + setPosting(false) } return ( @@ -158,6 +161,7 @@ export const CommentsTree = (props: Props) => { placeholder={t('Write a comment...')} onSubmit={(value) => handleSubmitComment(value)} setClear={clearEditor()} + isPosting={posting()} /> diff --git a/src/components/Editor/SimplifiedEditor.tsx b/src/components/Editor/SimplifiedEditor.tsx index 44401b1c..187fe25f 100644 --- a/src/components/Editor/SimplifiedEditor.tsx +++ b/src/components/Editor/SimplifiedEditor.tsx @@ -36,6 +36,7 @@ import { UploadModalContent } from './UploadModalContent' import { Figcaption } from './extensions/Figcaption' import { Figure } from './extensions/Figure' +import { Loading } from '../_shared/Loading' import styles from './SimplifiedEditor.module.scss' type Props = { @@ -58,6 +59,7 @@ type Props = { controlsAlwaysVisible?: boolean autoFocus?: boolean isCancelButtonVisible?: boolean + isPosting?: boolean } const DEFAULT_MAX_LENGTH = 400 @@ -365,12 +367,14 @@ const SimplifiedEditor = (props: Props) => {