Group six more clusters out of web/src/lib
Takes the flat module count from 66 to 42, continuing what admin/ and
calendar/ started.
lib/mailbox/ archiveDate, emptyFolder, folderMove, labelTree,
mailboxName, mailboxRoute
lib/sieve/ sieve, sieveApply, sieveFolders
lib/input/ keyboard, swipe, touch, listSelection, dropUpload
lib/notify/ notify, webpush, webpushEnable
lib/sw/ swCache, swFacts, staleBuild
lib/text/ html, markdown, text, emlName
FOUR THINGS THE FILENAMES GET WRONG, each checked by reading the file
rather than trusting what it is called:
- appFolder is not a mailbox. It is the `ihasmail` folder in JMAP
*Files*, where the client keeps signature images and synced settings.
It stays flat.
- format holds no formatting of text. It re-exports the date and clock
formatters, so it belongs with dates/datetime, not with text/.
- preview is the file viewer deciding what it can show without
downloading, and source is where to point someone asking for this
instance's AGPL source. Neither is about text.
- notify is not Web Push. It is the tab title, the favicon badge and
the new-mail sound -- in-app notification, which is why it sits with
webpush rather than under sw/ with the service worker's own concerns.
threadScroll stays flat too: it decides where a conversation opens, which
is view state rather than a gesture, and input/ is honest only if
everything in it interprets something the reader did.
No behavior change. Almost every reference was on the @/ alias; eight
relative imports in files that did not move, or that moved away from a
sibling, needed rewriting by hand.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Emptying a folder, and asking first.
|
||||
*
|
||||
* There are three ways in — the folder's right-click menu, the list's own
|
||||
* menu, and the banner across the top of Junk Mail — and they must not drift
|
||||
* apart in what they warn about. A folder can only be emptied when it is one
|
||||
* whose whole purpose is holding things you did not want: Deleted Items, or
|
||||
* Junk Mail.
|
||||
*
|
||||
* The wording differs between them for a reason. Emptying Deleted Items is
|
||||
* what anyone expects it to do. Emptying Junk Mail is the surprising one: the
|
||||
* messages do not travel to Deleted Items on the way out, so there is no
|
||||
* second chance to change your mind, and the dialog says so rather than
|
||||
* leaving it to be discovered.
|
||||
*/
|
||||
import { confirmDialog } from "@/ui/dialog";
|
||||
import { useMail } from "@/store/mail";
|
||||
import type { Id, MailboxRole } from "@/jmap/types";
|
||||
|
||||
export interface EmptyTarget {
|
||||
id: Id;
|
||||
name: string;
|
||||
role: MailboxRole;
|
||||
totalEmails: number;
|
||||
}
|
||||
|
||||
/** Whether this folder is one that may be emptied at all. */
|
||||
export function canEmpty(role: MailboxRole | undefined | null): boolean {
|
||||
return role === "trash" || role === "junk";
|
||||
}
|
||||
|
||||
const plural = (n: number) => `${n.toLocaleString()} message${n === 1 ? "" : "s"}`;
|
||||
|
||||
/** What the button or menu item is called, in the folder's own terms. */
|
||||
export function emptyLabel(target: Pick<EmptyTarget, "name" | "role">): string {
|
||||
return target.role === "junk" ? "Delete all spam" : `Empty ${target.name}`;
|
||||
}
|
||||
|
||||
/** Ask, then empty. Resolves once the emptying has been attempted, or declined. */
|
||||
export async function confirmAndEmpty(target: EmptyTarget): Promise<void> {
|
||||
if (!canEmpty(target.role)) return;
|
||||
const junk = target.role === "junk";
|
||||
const ok = await confirmDialog({
|
||||
title: junk ? `Delete all spam in “${target.name}”?` : `Empty “${target.name}”?`,
|
||||
message: junk
|
||||
? `All ${plural(target.totalEmails)} will be deleted permanently. They do not go to Deleted Items first, so this cannot be undone.`
|
||||
: `All ${plural(target.totalEmails)} will be permanently deleted.`,
|
||||
confirmLabel: junk ? "Delete all spam" : "Empty folder",
|
||||
danger: true,
|
||||
});
|
||||
if (ok) await useMail.getState().emptyMailbox(target.id);
|
||||
}
|
||||
Reference in New Issue
Block a user