From 8f6de58f6d185e9af7d6afc9f267ecf278fc6dcf Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 23 Jan 2024 16:42:05 +0300 Subject: [PATCH] drafts-fix --- .../Views/DraftsView/DraftsView.tsx | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/components/Views/DraftsView/DraftsView.tsx b/src/components/Views/DraftsView/DraftsView.tsx index f7da3fbf..1aed1a8e 100644 --- a/src/components/Views/DraftsView/DraftsView.tsx +++ b/src/components/Views/DraftsView/DraftsView.tsx @@ -1,6 +1,6 @@ import { openPage } from '@nanostores/router' import { clsx } from 'clsx' -import { createSignal, For, onMount, Show } from 'solid-js' +import { createSignal, createEffect, For, Show } from 'solid-js' import { useEditorContext } from '../../../context/editor' import { useSession } from '../../../context/session' @@ -13,28 +13,26 @@ import styles from './DraftsView.module.scss' export const DraftsView = () => { const { isAuthenticated, isSessionLoaded } = useSession() - const [drafts, setDrafts] = createSignal([]) const loadDrafts = async () => { - const loadedDrafts = await apiClient.getDrafts() - if (loadedDrafts) setDrafts(loadedDrafts.reverse()) - else setDrafts([]) + if (apiClient.private) { + const loadedDrafts = await apiClient.getDrafts() + setDrafts(loadedDrafts || []) + } } - onMount(() => { - loadDrafts() + createEffect(async () => { + if (isSessionLoaded()) await loadDrafts() }) const { actions: { publishShoutById, deleteShout }, } = useEditorContext() - const handleDraftDelete = (shout: Shout) => { + const handleDraftDelete = async (shout: Shout) => { const result = deleteShout(shout.id) - if (result) { - loadDrafts() - } + if (result) await loadDrafts() } const handleDraftPublish = (shout: Shout) => {