From afaa32384886a5b94efe39e7f8cb1da6864d4622 Mon Sep 17 00:00:00 2001 From: Matthias G Date: Sat, 1 Aug 2026 12:03:53 +0200 Subject: [PATCH] Delete drafts from the admin editor The editor could publish, archive and resume, but never remove. A draft whose id was lost was unreachable from the interface. --- messages/de.json | 5 +++- messages/en.json | 5 +++- src/components/admin/EntryEditor.tsx | 41 ++++++++++++++++++++++++++++ src/lib/entries.ts | 28 ++++++++++++++++++- src/lib/entry-actions.ts | 18 ++++++++++++ src/lib/entry-types.ts | 4 +++ 6 files changed, 98 insertions(+), 3 deletions(-) diff --git a/messages/de.json b/messages/de.json index 76154e4..770e752 100644 --- a/messages/de.json +++ b/messages/de.json @@ -402,7 +402,10 @@ "change": "Anderes Bild", "clear": "Bild entfernen", "upload": "Hochladen", - "close": "Schließen" + "close": "Schließen", + "delete": "Entwurf löschen", + "deleteConfirm": "Wirklich löschen?", + "deleting": "Wird gelöscht" }, "blocks": { "text": "Text", diff --git a/messages/en.json b/messages/en.json index 5977437..2850c01 100644 --- a/messages/en.json +++ b/messages/en.json @@ -402,7 +402,10 @@ "change": "Other image", "clear": "Remove image", "upload": "Upload", - "close": "Close" + "close": "Close", + "delete": "Delete draft", + "deleteConfirm": "Really delete?", + "deleting": "Deleting" }, "blocks": { "text": "Text", diff --git a/src/components/admin/EntryEditor.tsx b/src/components/admin/EntryEditor.tsx index 76841d6..d16f0e3 100644 --- a/src/components/admin/EntryEditor.tsx +++ b/src/components/admin/EntryEditor.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import Link from 'next/link' +import { useRouter } from 'next/navigation' import { useTranslations } from 'next-intl' import { TbArchive, @@ -14,6 +15,7 @@ import { TbPlus, TbRotate2, TbSend, + TbTrash, TbX, } from 'react-icons/tb' import { AdminField } from './AdminField' @@ -43,6 +45,7 @@ import { archiveEntry, loadEntryMedia, publishEntry, + removeEntry, resumeEntry, saveEntry, scheduleEntry, @@ -163,6 +166,8 @@ function localTime(date: Date): string { export function EntryEditor({ projects, types, media: initialMedia, accept, defaultProjectId, entry }: EntryEditorProps) { const t = useTranslations('admin.entries') + const router = useRouter() + const [asking, setAsking] = useState(false) const [form, setForm] = useState
(() => initialForm(entry, defaultProjectId, types[0]?.id ?? '')) const [media, setMedia] = useState(initialMedia) const [status, setStatus] = useState( @@ -401,6 +406,29 @@ export function EntryEditor({ projects, types, media: initialMedia, accept, defa setSavedAt(new Date()) } + async function remove() { + const id = idRef.current + + if (id === '') { + return + } + + setBusy(true) + setError(null) + + const result = await removeEntry(id) + + if (!result.ok) { + setBusy(false) + setAsking(false) + setError(result.error) + + return + } + + router.push(adminEntriesPath) + } + function update(patch: Partial) { setForm(current => ({ ...current, ...patch })) } @@ -497,6 +525,19 @@ export function EntryEditor({ projects, types, media: initialMedia, accept, defa {t('actions.save')} + {status && current === 'draft' ? ( + + ) : null} + {current === 'published' ? (