import { openPage } from '@nanostores/router' import { clsx } from 'clsx' import { For, Show, createEffect, createSignal, on } from 'solid-js' import { useEditorContext } from '../../../context/editor' import { useSession } from '../../../context/session' import { apiClient } from '../../../graphql/client/core' import { Shout } from '../../../graphql/schema/core.gen' import { router } from '../../../stores/router' import { Draft } from '../../Draft' import { Loading } from '../../_shared/Loading' import styles from './DraftsView.module.scss' export const DraftsView = () => { const { session } = useSession() const [drafts, setDrafts] = createSignal([]) createEffect( on( () => session(), async (s) => { if (s) { const loadedDrafts = await apiClient.getDrafts() setDrafts(loadedDrafts.reverse() || []) } }, ), ) const { publishShoutById, deleteShout } = useEditorContext() const handleDraftDelete = async (shout: Shout) => { const result = deleteShout(shout.id) if (result) { setDrafts((ddd) => ddd.filter((d) => d.id !== shout.id)) } } const handleDraftPublish = (shout: Shout) => { const result = publishShoutById(shout.id) if (result) { openPage(router, 'feed') } } return (
}>
{(draft) => ( )}
) }