Update App.tsx to include database export functionality
This commit is contained in:
15
src/App.tsx
15
src/App.tsx
@@ -2,10 +2,10 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|||||||
import { open, save } from "@tauri-apps/plugin-dialog";
|
import { open, save } from "@tauri-apps/plugin-dialog";
|
||||||
import { open as openExternal } from "@tauri-apps/plugin-shell";
|
import { open as openExternal } from "@tauri-apps/plugin-shell";
|
||||||
import { writeText as writeClipboardText } from "@tauri-apps/plugin-clipboard-manager";
|
import { writeText as writeClipboardText } from "@tauri-apps/plugin-clipboard-manager";
|
||||||
import { readTextFile, writeTextFile } from "@tauri-apps/plugin-fs";
|
import { copyFile, exists, readTextFile, remove, writeTextFile } from "@tauri-apps/plugin-fs";
|
||||||
import { Menu } from "@tauri-apps/api/menu";
|
import { Menu } from "@tauri-apps/api/menu";
|
||||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||||
import { appDataDir } from "@tauri-apps/api/path";
|
import { appDataDir, join } from "@tauri-apps/api/path";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { Compartment, EditorState, Transaction } from "@codemirror/state";
|
import { Compartment, EditorState, Transaction } from "@codemirror/state";
|
||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
deleteText,
|
deleteText,
|
||||||
deleteTextVersion,
|
deleteTextVersion,
|
||||||
discardDraft,
|
discardDraft,
|
||||||
|
exportDatabaseSnapshot,
|
||||||
getDraft,
|
getDraft,
|
||||||
getLatestManualVersion,
|
getLatestManualVersion,
|
||||||
getText,
|
getText,
|
||||||
@@ -70,6 +71,11 @@ const formatDate = (timestamp: number) => {
|
|||||||
return new Date(timestamp).toLocaleString();
|
return new Date(timestamp).toLocaleString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildDatabaseExportFilename = () => {
|
||||||
|
const timestamp = new Date().toISOString().replace(/\.\d{3}Z$/, "Z").replace(/:/g, "-");
|
||||||
|
return `textdb-backup-${timestamp}.db`;
|
||||||
|
};
|
||||||
|
|
||||||
type HistorySnapshot = {
|
type HistorySnapshot = {
|
||||||
body: string;
|
body: string;
|
||||||
lastPersistedBody: string;
|
lastPersistedBody: string;
|
||||||
@@ -87,6 +93,11 @@ type ConfirmState = {
|
|||||||
onConfirm: () => Promise<void> | void;
|
onConfirm: () => Promise<void> | void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type DbExportStatus = {
|
||||||
|
tone: "success" | "error";
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
type HistoryEntry = {
|
type HistoryEntry = {
|
||||||
id: string;
|
id: string;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user