import { openPage } from '@nanostores/router' import { clsx } from 'clsx' import { createSignal, createEffect, For, Show } 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 styles from './DraftsView.module.scss' export const DraftsView = () => { const { isAuthenticated, isSessionLoaded } = useSession() const [drafts, setDrafts] = createSignal([]) const loadDrafts = async () => { if (apiClient.private) { const loadedDrafts = await apiClient.getDrafts() setDrafts(loadedDrafts || []) } } createEffect(async () => { if (isSessionLoaded()) await loadDrafts() }) const { actions: { publishShoutById, deleteShout }, } = useEditorContext() const handleDraftDelete = async (shout: Shout) => { const result = deleteShout(shout.id) if (result) await loadDrafts() } const handleDraftPublish = (shout: Shout) => { const result = publishShoutById(shout.id) if (result) { openPage(router, 'feed') } } return (
{(draft) => ( )}
) }