Add Undo for book and chapter deletions

- Show an Undo toast after deleting a book from Home; Undo restores the
  folder from the system trash (XDG .trashinfo, URL-decoded path match).
- Chapter delete/cut now snapshots the chapter (title, color, content,
  position) and offers Undo to restore it in place.
- Add reusable showUndoToast/hideUndoToast and #undoToast UI + styles;
  expose restoreBook/restoreChapter over the preload bridge.
- Drop the now-redundant 'cannot be undone' confirm on chapter delete and
  the inaccurate 'permanently removes' wording on book delete.
This commit is contained in:
avi 2026-08-20 18:12:33 -05:00
commit aaa491424d
7 changed files with 210 additions and 16 deletions

View file

@ -170,7 +170,33 @@
}
step("exports", ex);
// New book auto-creates a folder inside Documents; then delete it.
// Chapter delete + undo (snapshot restore).
try {
const before = (await api.getChapterList()).length;
const cc = await api.getChapterContent("ch-one");
const delc = await api.deleteChapter("ch-one");
const afterDel = (await api.getChapterList()).length;
const restc = await api.restoreChapter({
id: "ch-one",
title: "Book_The_Lab",
color: null,
content: cc,
index: 0,
});
const afterRest = (await api.getChapterList()).length;
const cc2 = await api.getChapterContent("ch-one");
step("chapterUndo", {
before,
afterDel,
afterRest,
restored: cc2 === cc,
ok: !!(delc && delc.ok) && !!(restc && restc.ok),
});
} catch (e) {
step("chapterUndoErr", String(e));
}
// New book auto-creates a folder inside Documents; delete then undo.
const nb = await api.newBookNamed("Folio Selftest Temp");
step("newBookNamed", {
ok: !!(nb && nb.path && nb.title),
@ -180,6 +206,10 @@
if (nb && nb.path) {
const del = await api.deleteBook(nb.path);
step("deleteBook", del && del.ok ? "ok" : del && del.error);
if (del && del.ok) {
const rest = await api.restoreBook(nb.path);
step("restoreBook", rest && rest.ok ? "ok" : rest && rest.error);
}
}
out.ok = true;