import { SVGProps, memo } from "react"; import { Box, Paper, IconButton, Divider, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TablePagination, } from "@mui/material"; import { Notice } from "@/components/base"; import { Typography } from "@mui/material"; import { useLockFn } from "ahooks"; import { useTranslation } from "react-i18next"; import { Dayjs } from "dayjs"; import { deleteWebdavBackup, restoreWebDavBackup, restartApp, } from "@/services/cmds"; import DeleteIcon from "@mui/icons-material/Delete"; import RestoreIcon from "@mui/icons-material/Restore"; export type BackupFile = IWebDavFile & { platform: string; backup_time: Dayjs; allow_apply: boolean; }; export const DEFAULT_ROWS_PER_PAGE = 5; export interface BackupTableViewerProps { datasource: BackupFile[]; page: number; onPageChange: ( event: React.MouseEvent | null, page: number, ) => void; total: number; onRefresh: () => Promise; } export const BackupTableViewer = memo( ({ datasource, page, onPageChange, total, onRefresh, }: BackupTableViewerProps) => { const { t } = useTranslation(); const handleDelete = useLockFn(async (filename: string) => { await deleteWebdavBackup(filename); await onRefresh(); }); const handleRestore = useLockFn(async (filename: string) => { await restoreWebDavBackup(filename).then(() => { Notice.success(t("Restore Success, App will restart in 1s")); }); await restartApp(); }); return ( {t("Filename")} {t("Backup Time")} {t("Actions")} {datasource.length > 0 ? ( datasource?.map((file, index) => ( {file.platform === "windows" ? ( ) : file.platform === "linux" ? ( ) : ( )} {file.filename} {file.backup_time.fromNow()} { e.preventDefault(); const confirmed = await window.confirm( t("Confirm to delete this backup file?"), ); if (confirmed) { await handleDelete(file.filename); } }} > { e.preventDefault(); const confirmed = await window.confirm( t("Confirm to restore this backup file?"), ); if (confirmed) { await handleRestore(file.filename); } }} > )) ) : ( {t("No Backups")} )}
); }, ); function LinuxIcon(props: SVGProps) { return ( ); } function WindowsIcon(props: SVGProps) { return ( ); } function MacIcon(props: SVGProps) { return ( ); }