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
standalone/options/backup: create a different UI for the standalone mode
Adorian Doran33b1f579c69d
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex fba2ebba8c..08e185a350 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2077,7 +2077,10 @@"date-and-time": "Date & time","path": "Path","database_backed_up_to": "Database has been backed up to {{- backupFilePath}}",- "download_only_summary": "Backups are downloaded straight to your device; nothing is stored in the browser.",+ "standalone_heading": "Backup your Trilium data",+ "standalone_description": "Here you can download a backup of your Trilium knowledge base, or restore an existing backup.",+ "create_and_download": "Download backup",+ "upload_and_restore": "Restore backup","restart_for_backup": "Trilium needs to restart to back up your notes. You can go back to them as soon as it's done.\n\nRestart now?","no_backup_yet": "no backup yet","download": "Download",diff --git a/apps/client/src/widgets/type_widgets/options/backup.css b/apps/client/src/widgets/type_widgets/options/backup.cssindex f7d468cfc7..5caa7ef8d1 100644--- a/apps/client/src/widgets/type_widgets/options/backup.css+++ b/apps/client/src/widgets/type_widgets/options/backup.css@@ -22,6 +22,45 @@}}+/* The standalone page is this one block, so the setup form is asked to sit in a page among cards+ rather than fill a note's pane the way it does where it came from. */+.options-section.standalone-backup {+ .setup-form {+ height: auto;+ padding-inline: 0;+ }++ .tn-centered-form {+ margin-bottom: 0;+ }++ /* Sized for an empty note pane where it is the only thing on screen; here it shares a dialog+ with the rest of the settings, and at its own size it would be the settings. */+ .form-icon {+ font-size: 80px;+ }++ h3 {+ margin-bottom: 4px;+ }++ p {+ /* The form centres its children, which leaves a paragraph's own lines ragged. */+ max-width: 460px;+ text-align: center;+ color: var(--muted-text-color);+ }++ /* The form stacks whatever it is given, so the two actions are handed to it as one thing.+ They wrap where a phone's dialog cannot hold both. */+ .standalone-backup-actions {+ display: flex;+ flex-wrap: wrap;+ justify-content: center;+ gap: 8px;+ }+}+.backup-location .tn-card-section {display: grid;grid-template-columns: auto 1fr auto;diff --git a/apps/client/src/widgets/type_widgets/options/backup.status.spec.tsx b/apps/client/src/widgets/type_widgets/options/backup.status.spec.tsxindex dc62d798ac..312d1dd31c 100644--- a/apps/client/src/widgets/type_widgets/options/backup.status.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/backup.status.spec.tsx@@ -21,7 +21,7 @@ vi.mock("../../../services/i18n", async (importOriginal) => ({}));// Import AFTER the mocks (vi.mock is hoisted, but the component import must resolve the mocked deps).-import { BackupStatus, StandaloneBackupStatus } from "./backup";+import { BackupStatus, StandaloneBackupSection } from "./backup";let container: HTMLDivElement | undefined;@@ -80,7 +80,7 @@ describe("backing up where a backup is a download (standalone)", () => {const settle = () => new Promise((resolve) => setTimeout(resolve, 0));it("asks before restarting, then goes to the setup screen's backup step", async () => {- renderInto(<StandaloneBackupStatus />);+ renderInto(<StandaloneBackupSection />);backupNowButton()?.click();await settle();@@ -92,7 +92,7 @@ describe("backing up where a backup is a download (standalone)", () => {it("does nothing at all when the restart is declined", async () => {mocks.confirm.mockResolvedValue(false);- renderInto(<StandaloneBackupStatus />);+ renderInto(<StandaloneBackupSection />);backupNowButton()?.click();await settle();@@ -103,7 +103,7 @@ describe("backing up where a backup is a download (standalone)", () => {it("offers neither action where the app cannot start itself again", () => {// Both of them restart the application, so neither can be honoured without that.mocks.canBootToSetup.mockReturnValue(false);- renderInto(<StandaloneBackupStatus />);+ renderInto(<StandaloneBackupSection />);expect(backupNowButton()).toBeNull();expect(restoreButton()).toBeNull();diff --git a/apps/client/src/widgets/type_widgets/options/backup.tsx b/apps/client/src/widgets/type_widgets/options/backup.tsxindex 412d162280..e4947b78eb 100644--- a/apps/client/src/widgets/type_widgets/options/backup.tsx+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx@@ -27,6 +27,7 @@ import FormToggle from "../../react/FormToggle";import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";import Icon from "../../react/Icon";import Modal from "../../react/Modal";+import SetupForm from "../helpers/SetupForm";import DatabaseFileList from "./components/DatabaseFileList";import OptionsPageHeader from "./components/OptionsPageHeader";@@ -72,14 +73,22 @@ function StoredBackupSettings() {* schedule or format to configure, because nothing is ever stored.*/function StandaloneBackupSettings() {- return <OptionsPageHeader below={<StandaloneBackupStatus />} />;+ return (+ <>+ <OptionsPageHeader />+ <StandaloneBackupSection />+ </>+ );}/**- * The whole of what the standalone platform offers: back up, and restore. Both leave this screen- * behind, because both need the database held still, which only the setup screen provides.+ * The whole of what the standalone platform offers: back up, and restore.+ *+ * A page rather than a row of buttons, because there is nothing else on it: no list of backups, no+ * location and no schedule, since nothing is ever stored. Both actions leave for the setup screen,+ * which is where the database can be held still long enough to be copied or replaced.*/-export function StandaloneBackupStatus() {+export function StandaloneBackupSection() {/*** Restarts into the setup screen, where the backup is actually taken.*@@ -97,26 +106,28 @@ export function StandaloneBackupStatus() {}return (- <div className="backup-status">- <span className="backup-status-summary">{t("backup.download_only_summary")}</span>+ <div className="options-section standalone-backup">+ <SetupForm icon="bx bx-data">+ <h3>{t("backup.standalone_heading")}</h3>+ <p>{t("backup.standalone_description")}</p>- {canBootToSetup() && (- <>- <Button- name="restore-backup-button"- text={t("backup.restore_backup")}- size="micro"- onClick={() => bootToSetup({ targetScreen: "restore-backup" })}- />+ {canBootToSetup() && (+ <div className="standalone-backup-actions">+ <Button+ name="backup-database-now-button"+ text={t("backup.create_and_download")}+ kind="primary"+ onClick={() => void backUp()}+ />- <Button- name="backup-database-now-button"- text={t("backup.backup_now")}- size="micro"- onClick={() => void backUp()}- />- </>- )}+ <Button+ name="restore-backup-button"+ text={t("backup.upload_and_restore")}+ onClick={() => bootToSetup({ targetScreen: "restore-backup" })}+ />+ </div>+ )}+ </SetupForm></div>);}