Skip to content

Build your personal knowledge base with Trilium Notes

client/options/backup: upgrade to the new card style

Adorian Doran926d595af997
diff --git a/apps/client/src/widgets/type_widgets/options/advanced.tsx b/apps/client/src/widgets/type_widgets/options/advanced.tsx
index 2eed56c640..bfd28543f4 100644
--- a/apps/client/src/widgets/type_widgets/options/advanced.tsx
+++ b/apps/client/src/widgets/type_widgets/options/advanced.tsx
@@ -169,7 +169,6 @@ function ExistingAnonymizedDatabases({ databases, anonymizedFolderPath }: { data
locationDescription={anonymizedFolderPath && t("database_anonymization.anonymized_databases_location", { anonymizedFolder: anonymizedFolderPath })}
files={databases}
downloadEndpoint="api/database/anonymized/download"
- rowName="anonymized-database"
downloadText={t("database_anonymization.download")}
emptyIcon="bx bx-glasses"
emptyText={t("database_anonymization.no_anonymized_database_yet")}
diff --git a/apps/client/src/widgets/type_widgets/options/backup.css b/apps/client/src/widgets/type_widgets/options/backup.css
index b7e908af5c..5cb724c7dd 100644
--- a/apps/client/src/widgets/type_widgets/options/backup.css
+++ b/apps/client/src/widgets/type_widgets/options/backup.css
@@ -3,34 +3,10 @@
--bs-modal-width: 400px;
}
-/* One row per setting: what it is on the leading edge, what switches it on the trailing one. */
-.backup-options-row {
+/* The one action of the backups list, closing it off rather than sitting in line with a file. */
+.backup-now-section {
display: flex;
- align-items: center;
- gap: 8px;
-
- /* The controls keep their natural width. Left to shrink, a button's nowrap label spills across
- its own padding and ends up reading as though it had none; the label below gives instead. */
- > * {
- flex-shrink: 0;
- }
-
- .backup-options-label {
- display: flex;
- flex: 1 1 auto;
- flex-direction: column;
- gap: 2px;
- min-width: 0;
- }
-
- .backup-options-description {
- font-size: .85em;
- opacity: .7;
- }
-
- .btn {
- white-space: nowrap;
- }
+ justify-content: center;
}
.backup-location .tn-card-section {
diff --git a/apps/client/src/widgets/type_widgets/options/backup.tsx b/apps/client/src/widgets/type_widgets/options/backup.tsx
index 4d161c4210..1f63d01fdb 100644
--- a/apps/client/src/widgets/type_widgets/options/backup.tsx
+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx
@@ -10,7 +10,7 @@ import server from "../../../services/server";
import toast from "../../../services/toast";
import { isElectron } from "../../../services/utils";
import Button from "../../react/Button";
-import { Card, CardSection } from "../../react/Card";
+import { Card, CardOption, CardSection } from "../../react/Card";
import DirectoryLink from "../../react/DirectoryLink";
import FormPasswordWithConfirmation from "../../react/FormPasswordWithConfirmation";
import FormText from "../../react/FormText";
@@ -20,8 +20,6 @@ import Icon from "../../react/Icon";
import Modal from "../../react/Modal";
import DatabaseFileList from "./components/DatabaseFileList";
import OptionsPageHeader from "./components/OptionsPageHeader";
-import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";
-import OptionsSection from "./components/OptionsSection";
export default function BackupSettings() {
const [backups, setBackups] = useState<DatabaseBackup[]>([]);
@@ -55,31 +53,24 @@ export function BackupConfiguration() {
const [monthlyBackupEnabled, setMonthlyBackupEnabled] = useTriliumOptionBool("monthlyBackupEnabled");
return (
- <OptionsSection
- title={t("backup.automatic_backups_title")}
- description={t("backup.automatic_backups_description")}
- >
- <OptionsRowWithToggle
- name="daily-backup-enabled"
- label={t("backup.enable_daily_backup")}
- currentValue={dailyBackupEnabled}
- onChange={setDailyBackupEnabled}
- />
-
- <OptionsRowWithToggle
- name="weekly-backup-enabled"
- label={t("backup.enable_weekly_backup")}
- currentValue={weeklyBackupEnabled}
- onChange={setWeeklyBackupEnabled}
- />
-
- <OptionsRowWithToggle
- name="monthly-backup-enabled"
- label={t("backup.enable_monthly_backup")}
- currentValue={monthlyBackupEnabled}
- onChange={setMonthlyBackupEnabled}
- />
- </OptionsSection>
+ <div className="options-section backup-configuration">
+ <Card
+ heading={t("backup.automatic_backups_title")}
+ description={t("backup.automatic_backups_description")}
+ >
+ <CardOption name="daily-backup-enabled" label={t("backup.enable_daily_backup")}>
+ <FormToggle currentValue={dailyBackupEnabled} onChange={setDailyBackupEnabled} />
+ </CardOption>
+
+ <CardOption name="weekly-backup-enabled" label={t("backup.enable_weekly_backup")}>
+ <FormToggle currentValue={weeklyBackupEnabled} onChange={setWeeklyBackupEnabled} />
+ </CardOption>
+
+ <CardOption name="monthly-backup-enabled" label={t("backup.enable_monthly_backup")}>
+ <FormToggle currentValue={monthlyBackupEnabled} onChange={setMonthlyBackupEnabled} />
+ </CardOption>
+ </Card>
+ </div>
);
}
@@ -218,23 +209,18 @@ export function BackupOptions() {
return (
<div className="options-section backup-options">
<Card heading={t("backup.options_title")}>
- <CardSection className="backup-options-row">
- <span className="backup-options-label">
- {t("backup.enable_compression")}
- <small className="backup-options-description">{t("backup.enable_compression_description")}</small>
- </span>
-
+ <CardOption
+ name="backup-compression-enabled"
+ label={t("backup.enable_compression")}
+ description={t("backup.enable_compression_description")}
+ >
<FormToggle currentValue={compressionEnabled} onChange={setCompressionEnabled} />
- </CardSection>
-
- <CardSection className="backup-options-row">
- <span className="backup-options-label">
- {t("backup.enable_encryption")}
- <small className="backup-options-description">
- {passphrase.available ? t("backup.enable_encryption_description") : t("backup.no_keyring")}
- </small>
- </span>
+ </CardOption>
+ <CardOption
+ label={t("backup.enable_encryption")}
+ description={passphrase.available ? t("backup.enable_encryption_description") : t("backup.no_keyring")}
+ >
{passphrase.set ? (
<>
<Button
@@ -257,7 +243,7 @@ export function BackupOptions() {
onClick={() => setPasswordModalShown(true)}
/>
)}
- </CardSection>
+ </CardOption>
</Card>
<BackupPasswordModal
@@ -324,12 +310,11 @@ export function BackupList({ backups, backupFolderPath, refreshCallback }: { bac
files={backups}
fileBadges={fileBadges}
downloadEndpoint="api/database/backup/download"
- rowName="existing-backup"
downloadText={t("backup.download")}
emptyIcon="bx bx-archive"
emptyText={t("backup.no_backup_yet")}
>
- <OptionsRow name="backup-now" centered>
+ <CardSection className="backup-now-section">
<Button
name="backup-database-now-button"
text={t("backup.backup_database_now")}
@@ -346,7 +331,7 @@ export function BackupList({ backups, backupFolderPath, refreshCallback }: { bac
}
}}
/>
- </OptionsRow>
+ </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.tsx
index e4e5e04488..0619b1f1dc 100644
--- a/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx
@@ -9,9 +9,8 @@ import { formatSize } from "../../../../services/utils";
import { formatDateTime } from "../../../../utils/formatters";
import ActionButton from "../../../react/ActionButton";
import { Badge } from "../../../react/Badge";
+import { Card, CardOption, CardSection } from "../../../react/Card";
import NoItems from "../../../react/NoItems";
-import OptionsRow from "./OptionsRow";
-import OptionsSection from "./OptionsSection";
export interface DatabaseFile {
fileName: string;
@@ -34,17 +33,16 @@ interface DatabaseFileListProps<T extends DatabaseFile> {
files: T[];
/** Endpoint the per-file download links point to; the file path is appended as a query parameter. */
downloadEndpoint: string;
- rowName: string;
downloadText: string;
emptyIcon: string;
emptyText: string;
/** Labels individual files, for the ones that need telling apart — e.g. one kept somewhere else. */
fileBadges?: (file: T) => string[];
- /** Extra content rendered below the list (e.g. an action button). */
+ /** Extra card sections rendered below the list (e.g. an action button). */
children?: ComponentChildren;
}
-export default function DatabaseFileList<T extends DatabaseFile>({ title, locationDescription, files, downloadEndpoint, rowName, downloadText, emptyIcon, emptyText, fileBadges, children }: DatabaseFileListProps<T>) {
+export default function DatabaseFileList<T extends DatabaseFile>({ title, locationDescription, 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;
@@ -52,40 +50,43 @@ export default function DatabaseFileList<T extends DatabaseFile>({ title, locati
}), [files]);
return (
- <OptionsSection
- title={title}
- description={locationDescription && (
- <span className="selectable-text">{locationDescription}</span>
- )}
- >
- {sortedFiles.length > 0 ? (
- sortedFiles.map((file) => (
- <OptionsRow
- key={file.filePath}
- name={rowName}
- label={
- <span className="database-file-label">
- <span className="selectable-text">{file.fileName}</span>
- {fileBadges?.(file).map((badge) => (
- <Badge key={badge} className="database-file-badge" text={badge} outline />
- ))}
- </span>
- }
- description={describeFile(file)}
- >
- <ActionButton
- icon="bx bx-download"
- text={downloadText}
- onClick={() => open.download(open.getUrlForDownload(`${downloadEndpoint}?filePath=${encodeURIComponent(file.filePath)}`))}
- />
- </OptionsRow>
- ))
- ) : (
- <NoItems icon={emptyIcon} text={emptyText} />
- )}
+ <div className="options-section database-file-list">
+ <Card
+ heading={title}
+ description={locationDescription && (
+ <span className="selectable-text">{locationDescription}</span>
+ )}
+ >
+ {sortedFiles.length > 0 ? (
+ sortedFiles.map((file) => (
+ <CardOption
+ key={file.filePath}
+ label={
+ <span className="database-file-label">
+ <span className="selectable-text">{file.fileName}</span>
+ {fileBadges?.(file).map((badge) => (
+ <Badge key={badge} className="database-file-badge" text={badge} outline />
+ ))}
+ </span>
+ }
+ description={describeFile(file)}
+ >
+ <ActionButton
+ icon="bx bx-download"
+ text={downloadText}
+ onClick={() => open.download(open.getUrlForDownload(`${downloadEndpoint}?filePath=${encodeURIComponent(file.filePath)}`))}
+ />
+ </CardOption>
+ ))
+ ) : (
+ <CardSection>
+ <NoItems icon={emptyIcon} text={emptyText} size="small" />
+ </CardSection>
+ )}
- {children}
- </OptionsSection>
+ {children}
+ </Card>
+ </div>
);
}