mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-13 12:13:42 +01:00
The trash button and its hotkey open a confirm dialog instead of a dropdown. Its Don't ask again checkbox saves a preference that Settings turns back on under Traffic, as Confirm before clearing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
996 B
TypeScript
33 lines
996 B
TypeScript
import { atomWithStorage, createJSONStorage } from "jotai/utils";
|
|
|
|
/**
|
|
* Clearing traffic asks first, until "Don't ask again" is checked in its dialog. The switch in
|
|
* Settings turns the asking back on.
|
|
*/
|
|
export const confirmClearFlowsAtom = atomWithStorage<boolean>(
|
|
"confirm_clear_flows",
|
|
true,
|
|
// Read through globalThis so tests, which have no localStorage, can import this
|
|
createJSONStorage<boolean>(() => globalThis.localStorage),
|
|
{ getOnInit: true },
|
|
);
|
|
|
|
/** What Clear does now: nothing, ask first, or clear at once */
|
|
export type ClearFlowsAction = "disabled" | "confirm" | "clear";
|
|
|
|
export function clearFlowsAction({
|
|
total,
|
|
locked,
|
|
confirm,
|
|
}: {
|
|
/** Flows there are to clear */
|
|
total: number;
|
|
/** Captured traffic is locked, so none of it can be read */
|
|
locked: boolean;
|
|
/** The saved preference to ask before clearing */
|
|
confirm: boolean;
|
|
}): ClearFlowsAction {
|
|
if (locked || total === 0) return "disabled";
|
|
return confirm ? "confirm" : "clear";
|
|
}
|