-
{drafts.map((draft) => {
const { updatedAt, key, draftStatus, replyTo } = draft;
const updatedAtDate = new Date(updatedAt);
return (
- ); })}
> ) : (
No drafts found.
)}import './drafts.css'; import { useEffect, useMemo, useReducer, useState } from 'react'; import { api } from '../utils/api'; import db from '../utils/db'; import niceDateTime from '../utils/nice-date-time'; import states from '../utils/states'; import { getCurrentAccountNS } from '../utils/store-utils'; import Icon from './icon'; import Loader from './loader'; function Drafts() { const { masto } = api(); const [uiState, setUIState] = useState('default'); const [drafts, setDrafts] = useState([]); const [reloadCount, reload] = useReducer((c) => c + 1, 0); useEffect(() => { setUIState('loading'); (async () => { try { const keys = await db.drafts.keys(); if (keys.length) { const ns = getCurrentAccountNS(); const ownKeys = keys.filter((key) => key.startsWith(ns)); if (ownKeys.length) { const drafts = await db.drafts.getMany(ownKeys); drafts.sort( (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(), ); setDrafts(drafts); } else { setDrafts([]); } } else { setDrafts([]); } setUIState('default'); } catch (e) { console.error(e); setUIState('error'); } })(); }, [reloadCount]); const hasDrafts = drafts?.length > 0; return (
> ) : (
No drafts found.
)}