Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/options/backup: add a header for the page
Adorian Doranf45d56090723
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f7bee599c1..c718cd6bed 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2066,7 +2066,8 @@"default_location": "Default location","backup_recommendation": "It's recommended to keep the backup turned on, but this can make application startup slow with large databases and/or slow storage devices.","backup_now": "Backup now",- "backup_database_now": "Backup database now",+ "backups_summary_one": "{{count}} backup, the most recent from {{age}} ago.",+ "backups_summary_other": "{{count}} backups, the most recent from {{age}} ago.","existing_backups": "Existing backups","date-and-time": "Date & time","path": "Path",diff --git a/apps/client/src/widgets/type_widgets/options/advanced.tsx b/apps/client/src/widgets/type_widgets/options/advanced.tsxindex bfd28543f4..765f0199ca 100644--- a/apps/client/src/widgets/type_widgets/options/advanced.tsx+++ b/apps/client/src/widgets/type_widgets/options/advanced.tsx@@ -166,7 +166,11 @@ function ExistingAnonymizedDatabases({ databases, anonymizedFolderPath }: { datareturn (<DatabaseFileListtitle={t("database_anonymization.existing_anonymized_databases")}- locationDescription={anonymizedFolderPath && t("database_anonymization.anonymized_databases_location", { anonymizedFolder: anonymizedFolderPath })}+ description={anonymizedFolderPath && (+ <span className="selectable-text">+ {t("database_anonymization.anonymized_databases_location", { anonymizedFolder: anonymizedFolderPath })}+ </span>+ )}files={databases}downloadEndpoint="api/database/anonymized/download"downloadText={t("database_anonymization.download")}diff --git a/apps/client/src/widgets/type_widgets/options/backup.css b/apps/client/src/widgets/type_widgets/options/backup.cssindex 5cb724c7dd..0b90bf0371 100644--- a/apps/client/src/widgets/type_widgets/options/backup.css+++ b/apps/client/src/widgets/type_widgets/options/backup.css@@ -3,10 +3,23 @@--bs-modal-width: 400px;}-/* The one action of the backups list, closing it off rather than sitting in line with a file. */-.backup-now-section {+/* How the backups stand, with the button that makes one taking the end of the same row. */+.backup-status {display: flex;- justify-content: center;+ align-items: center;+ gap: 8px;++ .backup-status-summary {+ flex: 1 1 auto;+ min-width: 0;+ color: var(--muted-text-color);+ font-size: .9em;+ }++ .btn {+ flex-shrink: 0;+ white-space: nowrap;+ }}.backup-location .tn-card-section {diff --git a/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx b/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsxindex efe25f3870..232be5b6b8 100644--- a/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/backup.location.spec.tsx@@ -154,11 +154,7 @@ describe("BackupList: telling the two locations apart", () => {function renderList(folderPath: string, files: string[]) {return renderInto(- <BackupList- backups={files.map(backup)}- backupFolderPath={folderPath}- refreshCallback={refreshCallback}- />+ <BackupList backups={files.map(backup)} backupFolderPath={folderPath} />);}diff --git a/apps/client/src/widgets/type_widgets/options/backup.tsx b/apps/client/src/widgets/type_widgets/options/backup.tsxindex d7e9a2e3af..b743f2c87f 100644--- a/apps/client/src/widgets/type_widgets/options/backup.tsx+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx@@ -1,6 +1,6 @@import "./backup.css";-import { BackupDatabaseNowResponse, BackupPassphraseStatus, DatabaseBackup, ExistingBackupsResponse } from "@triliumnext/commons";+import { BackupDatabaseNowResponse, BackupPassphraseStatus, DatabaseBackup, dayjs, ExistingBackupsResponse } from "@triliumnext/commons";import { useCallback, useEffect, useRef, useState } from "preact/hooks";import dialogService from "../../../services/dialog";@@ -36,8 +36,8 @@ export default function BackupSettings() {return (<>- <OptionsPageHeader />- <BackupList backups={backups} backupFolderPath={backupFolderPath} refreshCallback={refreshBackups} />+ <OptionsPageHeader below={<BackupStatus backups={backups} refreshCallback={refreshBackups} />} />+ <BackupList backups={backups} backupFolderPath={backupFolderPath} />{/* Absent where there is no user-accessible location at all, e.g. backups kept in OPFS. */}{backupFolderPath && <BackupLocation backupFolderPath={backupFolderPath} refreshCallback={refreshBackups} />}<BackupConfiguration />@@ -47,6 +47,53 @@ export default function BackupSettings() {);}+/**+ * How the backups stand, and the one action that makes one now rather than on a schedule. Part of the+ * page's own header rather than of the list below it: the list card answers for what it holds, which+ * is not the same as what the page is for.+ */+function BackupStatus({ backups, refreshCallback }: { backups: DatabaseBackup[]; refreshCallback: () => void }) {+ const [backupInProgress, setBackupInProgress] = useState(false);++ return (+ <div className="backup-status">+ <span className="backup-status-summary">{summarizeBackups(backups)}</span>++ <Button+ name="backup-database-now-button"+ text={t("backup.backup_now")}+ size="micro"+ disabled={backupInProgress}+ onClick={async () => {+ setBackupInProgress(true);+ try {+ const { backupFile } = await server.post<BackupDatabaseNowResponse>("database/backup-database");+ toast.showMessage(t("backup.database_backed_up_to", { backupFilePath: backupFile }), 10000);+ refreshCallback();+ } finally {+ setBackupInProgress(false);+ }+ }}+ />+ </div>+ );+}++/**+ * How many backups there are and how long ago the last one was made — the two things the list itself+ * only answers by being read through. Nothing is said while there are none: the list stands empty+ * right below, which states it more plainly than a sentence could.+ */+function summarizeBackups(backups: DatabaseBackup[]) {+ if (!backups.length) {+ return null;+ }++ const mostRecent = backups.reduce((latest, backup) => (backup.mtime > latest.mtime ? backup : latest));++ return t("backup.backups_summary", { count: backups.length, age: dayjs(mostRecent.mtime).fromNow(true) });+}+export function BackupConfiguration() {const [dailyBackupEnabled, setDailyBackupEnabled] = useTriliumOptionBool("dailyBackupEnabled");const [weeklyBackupEnabled, setWeeklyBackupEnabled] = useTriliumOptionBool("weeklyBackupEnabled");@@ -280,8 +327,7 @@ function BackupPasswordModal({ show, onHidden, onSave }: { show: boolean; onHidd);}-export function BackupList({ backups, backupFolderPath, refreshCallback }: { backups: DatabaseBackup[]; backupFolderPath: string | null; refreshCallback: () => void }) {- const [backupInProgress, setBackupInProgress] = useState(false);+export function BackupList({ backups, backupFolderPath }: { backups: DatabaseBackup[]; backupFolderPath: string | null }) {const [customDir] = useTriliumOption("customDbBackupDir");// What a row cannot say for itself: the format it was written in, and — with a custom location in@@ -313,26 +359,7 @@ export function BackupList({ backups, backupFolderPath, refreshCallback }: { bacdownloadText={t("backup.download")}emptyIcon="bx bx-archive"emptyText={t("backup.no_backup_yet")}- >- <CardSection className="backup-now-section">- <Button- name="backup-database-now-button"- text={t("backup.backup_database_now")}- size="micro"- disabled={backupInProgress}- onClick={async () => {- setBackupInProgress(true);- try {- const { backupFile } = await server.post<BackupDatabaseNowResponse>("database/backup-database");- toast.showMessage(t("backup.database_backed_up_to", { backupFilePath: backupFile }), 10000);- refreshCallback();- } finally {- setBackupInProgress(false);- }- }}- />- </CardSection>- </DatabaseFileList>+ />);}diff --git a/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx b/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsxindex 0619b1f1dc..c58ed1bc75 100644--- a/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx+++ b/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx@@ -27,8 +27,8 @@ export interface DatabaseFile {interface DatabaseFileListProps<T extends DatabaseFile> {title: string;- /** Sentence describing where the files are stored; omitted when there is no user-accessible location. */- locationDescription?: string | null;+ /** Sentence introducing the list — what it holds, or where the files are stored. */+ description?: ComponentChildren;/** Displayed sorted by modification date & time in a descending order. */files: T[];/** Endpoint the per-file download links point to; the file path is appended as a query parameter. */@@ -42,7 +42,7 @@ interface DatabaseFileListProps<T extends DatabaseFile> {children?: ComponentChildren;}-export default function DatabaseFileList<T extends DatabaseFile>({ title, locationDescription, files, downloadEndpoint, downloadText, emptyIcon, emptyText, fileBadges, children }: DatabaseFileListProps<T>) {+export default function DatabaseFileList<T extends DatabaseFile>({ title, description, files, downloadEndpoint, downloadText, emptyIcon, emptyText, fileBadges, children }: DatabaseFileListProps<T>) {const sortedFiles = useMemo(() => [...files].sort((a, b) => {if (a.mtime < b.mtime) return 1;if (a.mtime > b.mtime) return -1;@@ -51,12 +51,7 @@ export default function DatabaseFileList<T extends DatabaseFile>({ title, locatireturn (<div className="options-section database-file-list">- <Card- heading={title}- description={locationDescription && (- <span className="selectable-text">{locationDescription}</span>- )}- >+ <Card heading={title} description={description}>{sortedFiles.length > 0 ? (sortedFiles.map((file) => (<CardOption