Skip to content

Build your personal knowledge base with Trilium Notes

Merge branch 'main' of https://github.com/TriliumNext/Trilium into feat/backup-options-improvements

Adorian Doran72a12b56ee4d
diff --cc apps/client/src/widgets/type_widgets/options/backup.tsx
index 716421c1f7,14802bfd02..9241a05a80
--- a/apps/client/src/widgets/type_widgets/options/backup.tsx
+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx
@@@ -1,14 -1,9 +1,15 @@@
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 { describeDatabaseFormat } from "../../../services/database_files";
import dialogService from "../../../services/dialog";
import { t } from "../../../services/i18n";
import options from "../../../services/options";
diff --cc apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx
index de40ac57f0,e1e2116a3a..8013a5e2df
--- a/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/DatabaseFileList.tsx
@@@ -3,27 -3,15 +3,14 @@@ import "./DatabaseFileList.css"
import { ComponentChildren } from "preact";
import { useMemo } from "preact/hooks";
- import { t } from "../../../../services/i18n";
+ import { type DatabaseFile, describeDatabaseFile } from "../../../../services/database_files";
import open from "../../../../services/open";
- 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 DatabaseFileBadges from "../../../react/DatabaseFileBadges";
import NoItems from "../../../react/NoItems";
-import OptionsRow from "./OptionsRow";
-import OptionsSection from "./OptionsSection";
- export interface DatabaseFile {
- fileName: string;
- filePath: string;
- mtime: Date;
- /** Size of the file, in bytes. */
- fileSize: number;
- /**
- * Size of the database the file was made from, in bytes, where that differs from the file's own
- * size — a compressed backup, say. Both are then shown, so the saving is visible.
- */
- plaintextSize?: number;
- }
+ export type { DatabaseFile };
interface DatabaseFileListProps<T extends DatabaseFile> {
title: string;
@@@ -53,64 -39,37 +40,41 @@@ export default function DatabaseFileLis
}), [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>
- <DatabaseFileBadges badges={fileBadges?.(file) ?? []} />
- </span>
- }
- description={describeDatabaseFile(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={description}>
+ {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
- />
- ))}
++ <DatabaseFileBadges badges={fileBadges?.(file) ?? []} />
+ </span>
+ }
- description={describeFile(file)}
++ description={describeDatabaseFile(file)}
+ >
+ <ActionButton
+ icon="bx bx-download"
+ text={downloadText}
+ onClick={() => downloadFile(downloadEndpoint, file.filePath)}
+ />
+ </CardOption>
+ ))
+ ) : (
+ <CardSection>
+ <NoItems icon={emptyIcon} text={emptyText} size="small" />
+ </CardSection>
+ )}
- {children}
- </OptionsSection>
+ {children}
+ </Card>
+ </div>
);
}
+
+function downloadFile(downloadEndpoint: string, filePath: string) {
+ const url = `${downloadEndpoint}?filePath=${encodeURIComponent(filePath)}`;
+
+ open.download(open.getUrlForDownload(url));
+}
-
- /**
- * When the file was written, and how big it is. A file made from a database larger than itself states
- * both, so what compressing it saved is visible rather than having to be worked out.
- */
- function describeFile(file: DatabaseFile): string {
- const parts = [file.mtime ? formatDateTime(file.mtime) : "-"];
-
- if (file.plaintextSize && file.plaintextSize !== file.fileSize) {
- parts.push(formatSize(file.plaintextSize), t("database_file_list.size_on_disk", { size: formatSize(file.fileSize) }));
- } else {
- parts.push(formatSize(file.fileSize));
- }
-
- return parts.join(" • ");
- }