mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-14 22:10:32 +08:00
fix(backup): prevent immediate deletion before confirmation dialog
This commit is contained in:
parent
4835d68222
commit
fd5bddeb80
@ -33,6 +33,14 @@ export type BackupFile = {
|
|||||||
|
|
||||||
export const DEFAULT_ROWS_PER_PAGE = 5;
|
export const DEFAULT_ROWS_PER_PAGE = 5;
|
||||||
|
|
||||||
|
type ConfirmFn = (message?: string) => boolean | Promise<boolean>;
|
||||||
|
|
||||||
|
// Normalizes synchronous and async confirm implementations.
|
||||||
|
const confirmAsync = async (message: string): Promise<boolean> => {
|
||||||
|
const confirmFn = window.confirm as unknown as ConfirmFn;
|
||||||
|
return await confirmFn.call(window, message);
|
||||||
|
};
|
||||||
|
|
||||||
interface BackupTableViewerProps {
|
interface BackupTableViewerProps {
|
||||||
datasource: BackupFile[];
|
datasource: BackupFile[];
|
||||||
page: number;
|
page: number;
|
||||||
@ -154,13 +162,13 @@ export const BackupTableViewer = memo(
|
|||||||
aria-label={t("Delete")}
|
aria-label={t("Delete")}
|
||||||
size="small"
|
size="small"
|
||||||
title={t("Delete Backup")}
|
title={t("Delete Backup")}
|
||||||
onClick={(e: React.MouseEvent) => {
|
onClick={async (e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const confirmed = window.confirm(
|
const confirmed = await confirmAsync(
|
||||||
t("Confirm to delete this backup file?"),
|
t("Confirm to delete this backup file?"),
|
||||||
);
|
);
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
void handleDelete(file.filename);
|
await handleDelete(file.filename);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -177,13 +185,13 @@ export const BackupTableViewer = memo(
|
|||||||
size="small"
|
size="small"
|
||||||
title={t("Restore Backup")}
|
title={t("Restore Backup")}
|
||||||
disabled={!file.allow_apply}
|
disabled={!file.allow_apply}
|
||||||
onClick={(e: React.MouseEvent) => {
|
onClick={async (e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const confirmed = window.confirm(
|
const confirmed = await confirmAsync(
|
||||||
t("Confirm to restore this backup file?"),
|
t("Confirm to restore this backup file?"),
|
||||||
);
|
);
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
void handleRestore(file.filename);
|
await handleRestore(file.filename);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user