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/search: make some commands searchable
Adorian Dorand705950f2110
diff --git a/apps/client/src/widgets/type_widgets/options/backup.tsx b/apps/client/src/widgets/type_widgets/options/backup.tsxindex 84514693be..2a3bf3e9bb 100644--- a/apps/client/src/widgets/type_widgets/options/backup.tsx+++ b/apps/client/src/widgets/type_widgets/options/backup.tsx@@ -61,6 +61,8 @@ function StoredBackupSettings() {<BackupConfiguration />{/* Desktop only: the passphrase needs an OS keyring to live in, which only the desktop has. */}{isElectron() && <BackupOptions />}++ <BackupActions refreshCallback={refreshBackups} /></>);}@@ -157,7 +159,7 @@ interface BackupStatusProps {* holds, which is not the same as what the page is for.*/export function BackupStatus({ backups, refreshCallback }: BackupStatusProps) {- const [backupInProgress, setBackupInProgress] = useState(false);+ const { backUpNow, backupInProgress } = useBackupNow(refreshCallback);return (<div className="backup-status">@@ -179,27 +181,71 @@ export function BackupStatus({ backups, refreshCallback }: BackupStatusProps) {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);- }- }}+ onClick={backUpNow}/></div>);}+/**+ * Taking a backup there and then, held apart from the button so that the settings search can offer+ * the same command without a second copy of what it does.+ */+function useBackupNow(refreshCallback: () => void) {+ const [ backupInProgress, setBackupInProgress ] = useState(false);++ const backUpNow = useCallback(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);+ }+ }, [ refreshCallback ]);++ return { backUpNow, backupInProgress };+}++/**+ * The page's own commands, which live in its header and so are out of the search's reach. Offered+ * here as the settings they stand beside are, operated where they are found.+ */+function BackupActions({ refreshCallback }: { refreshCallback: () => void }) {+ const { backUpNow, backupInProgress } = useBackupNow(refreshCallback);++ return (+ <Card filterOnly heading={t("settings.related_actions")}>+ <OptionCardSection label={t("backup.backup_now")}>+ <Button+ text={t("backup.backup_now")}+ disabled={backupInProgress}+ onClick={backUpNow}+ />+ </OptionCardSection>++ {canBootToSetup() && (+ <OptionCardSection+ label={t("backup.restore_backup")}+ description={t("backup.restart_for_restore")}+ >+ <Button+ text={t("backup.restore_backup")}+ onClick={() => void restoreInSetup()}+ />+ </OptionCardSection>+ )}+ </Card>+ );+}+export function BackupConfiguration() {const [dailyBackupEnabled, setDailyBackupEnabled] = useTriliumOptionBool("dailyBackupEnabled");const [weeklyBackupEnabled, setWeeklyBackupEnabled] = useTriliumOptionBool("weeklyBackupEnabled");diff --git a/apps/client/src/widgets/type_widgets/options/etapi.tsx b/apps/client/src/widgets/type_widgets/options/etapi.tsxindex e7810decca..c6e2f740ad 100644--- a/apps/client/src/widgets/type_widgets/options/etapi.tsx+++ b/apps/client/src/widgets/type_widgets/options/etapi.tsx@@ -75,6 +75,17 @@ export default function EtapiSettings() {/><TokenList tokens={tokens} />++ {/* The page's one command lives in its header, out of the search's reach. Offered+ here as the settings on other pages are: named, and operated where it is found. */}+ <Card filterOnly heading={t("settings.related_actions")}>+ <OptionCardSection+ label={t("etapi.create_token")}+ description={t("etapi.description")}+ >+ <Button text={t("etapi.create_token")} onClick={createTokenCallback} />+ </OptionCardSection>+ </Card></>);}diff --git a/apps/client/src/widgets/type_widgets/options/search_page.css b/apps/client/src/widgets/type_widgets/options/search_page.cssindex 0ac2e3c6cc..f237655ac5 100644--- a/apps/client/src/widgets/type_widgets/options/search_page.css+++ b/apps/client/src/widgets/type_widgets/options/search_page.css@@ -30,9 +30,27 @@}}+/* A page's header is chrome, bar one thing: the switch governing a whole page (the LLM and+ spellcheck pages) is a setting like any other, and sits there only because it rules the page.+ So the band itself stands down, along with the name it would print — which is the name of+ whichever page the dialog last showed, not the one it heads here — and what matched stays. */+.options-search-page .options-page-header {+ position: static;+ border-bottom: none;+ padding-block: 0;++ .options-page-header-main {+ display: none;+ }++ .options-page-header-below > :not(.tn-filter-match):not(:has(.tn-filter-match)) {+ display: none;+ }+}+/* The field says what is being done, so on a small screen the room above the results is worth more- than a banner repeating it. (The narrow flow drops it anyway, by the rule in OptionsPageHeader.css- that takes down a banner carrying nothing but a name.) */+ than a banner repeating it. (The narrow flow drops it anyway, by the rule in+ OptionsPageHeader.css that takes down a banner carrying nothing but a name.) */body.mobile .options-search .options-page-header {display: none;}@@ -45,8 +63,10 @@ body.mobile .options-search .options-page-header {** The page itself is a filter scope, and goes when empty by the rule in filter.css.*/-.options-search-page > :not(.options-search-page-title, .tn-filter-match):not(:has(.tn-filter-match)) {- display: none;+.options-search-page {+ > :not(.options-search-page-title, .tn-filter-match):not(:has(.tn-filter-match)) {+ display: none;+ }}/* Nothing to stand in for once the search has something to show. */diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsxindex 09ab8c76c4..c6b37f0e3b 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx@@ -197,6 +197,16 @@ export default function ShortcutSettings() {/>)}</div>++ {/* "Reset all" says little once it is read away from the page it belongs to, so the+ words it is found by come from what the action asks before it runs. */}+ <Card filterOnly+ heading={t("settings.related_actions")}+ filterExtraKeywords={t("shortcuts.confirm_reset")}>+ <OptionCardSection label={t("shortcuts.set_all_to_default")}>+ <Button text={t("shortcuts.set_all_to_default")} onClick={resetShortcuts} />+ </OptionCardSection>+ </Card></>);}