drafts-fix
This commit is contained in:
parent
d38adbfc61
commit
8f6de58f6d
|
@ -1,6 +1,6 @@
|
||||||
import { openPage } from '@nanostores/router'
|
import { openPage } from '@nanostores/router'
|
||||||
import { clsx } from 'clsx'
|
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 { useEditorContext } from '../../../context/editor'
|
||||||
import { useSession } from '../../../context/session'
|
import { useSession } from '../../../context/session'
|
||||||
|
@ -13,28 +13,26 @@ import styles from './DraftsView.module.scss'
|
||||||
|
|
||||||
export const DraftsView = () => {
|
export const DraftsView = () => {
|
||||||
const { isAuthenticated, isSessionLoaded } = useSession()
|
const { isAuthenticated, isSessionLoaded } = useSession()
|
||||||
|
|
||||||
const [drafts, setDrafts] = createSignal<Shout[]>([])
|
const [drafts, setDrafts] = createSignal<Shout[]>([])
|
||||||
|
|
||||||
const loadDrafts = async () => {
|
const loadDrafts = async () => {
|
||||||
|
if (apiClient.private) {
|
||||||
const loadedDrafts = await apiClient.getDrafts()
|
const loadedDrafts = await apiClient.getDrafts()
|
||||||
if (loadedDrafts) setDrafts(loadedDrafts.reverse())
|
setDrafts(loadedDrafts || [])
|
||||||
else setDrafts([])
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
createEffect(async () => {
|
||||||
loadDrafts()
|
if (isSessionLoaded()) await loadDrafts()
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
actions: { publishShoutById, deleteShout },
|
actions: { publishShoutById, deleteShout },
|
||||||
} = useEditorContext()
|
} = useEditorContext()
|
||||||
|
|
||||||
const handleDraftDelete = (shout: Shout) => {
|
const handleDraftDelete = async (shout: Shout) => {
|
||||||
const result = deleteShout(shout.id)
|
const result = deleteShout(shout.id)
|
||||||
if (result) {
|
if (result) await loadDrafts()
|
||||||
loadDrafts()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDraftPublish = (shout: Shout) => {
|
const handleDraftPublish = (shout: Shout) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user