drafts-fix

This commit is contained in:
Untone 2024-01-23 16:42:05 +03:00
parent d38adbfc61
commit 8f6de58f6d

View File

@ -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<Shout[]>([])
const loadDrafts = async () => {
if (apiClient.private) {
const loadedDrafts = await apiClient.getDrafts()
if (loadedDrafts) setDrafts(loadedDrafts.reverse())
else setDrafts([])
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) => {