drafts-fix
This commit is contained in:
parent
d38adbfc61
commit
8f6de58f6d
|
@ -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 () => {
|
||||
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) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user