mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 14:34:24 +01:00
use session storage for state
f2
This commit is contained in:
parent
6dcc3a7e81
commit
9c86145ff8
@ -6,7 +6,7 @@ import attributes from "../../services/attributes";
|
|||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import toast from "../../services/toast";
|
import toast from "../../services/toast";
|
||||||
import froca from "../../services/froca";
|
import froca from "../../services/froca";
|
||||||
import { useContext, useEffect, useState } from "preact/hooks";
|
import { useContext, useEffect, useMemo, useState } from "preact/hooks";
|
||||||
import { ParentComponent } from "../react/react_utils";
|
import { ParentComponent } from "../react/react_utils";
|
||||||
import { useTriliumEvent } from "../react/hooks";
|
import { useTriliumEvent } from "../react/hooks";
|
||||||
import appContext from "../../components/app_context";
|
import appContext from "../../components/app_context";
|
||||||
@ -73,24 +73,29 @@ export default function SearchDefinitionTab({ note, ntxId, hidden }: TabContext)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const executionState = useMemo(() => {
|
||||||
|
const AUTO_EXEC_KEY = "lastAutoExecutedSearchNote";
|
||||||
|
return {
|
||||||
|
load: () => sessionStorage.getItem(AUTO_EXEC_KEY),
|
||||||
|
save: (noteId: string) => sessionStorage.setItem(AUTO_EXEC_KEY, noteId),
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function autoExecute() {
|
async function autoExecute() {
|
||||||
if (note?.type !== 'search' || !note?.hasLabel('autoExecuteSearch')) {
|
if (!note || note?.type !== "search" || !note?.hasLabel("autoExecuteSearch")) {
|
||||||
|
executionState.save("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Executing search');
|
const lastExecutedNoteId = executionState.load();
|
||||||
|
if (lastExecutedNoteId !== note.noteId) {
|
||||||
|
executionState.save(note.noteId);
|
||||||
|
|
||||||
// Only execute if no results exist yet
|
await refreshResults();
|
||||||
await refreshResults();
|
|
||||||
|
|
||||||
console.log('Executed search');
|
parentComponent?.triggerCommand("toggleRibbonTabBookProperties", {});
|
||||||
|
}
|
||||||
const hasResults = note.children && note.children.length > 0;
|
|
||||||
|
|
||||||
if (hasResults) {
|
|
||||||
parentComponent?.triggerCommand('toggleRibbonTabBookProperties', { ntxId });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
autoExecute();
|
autoExecute();
|
||||||
}, [note]);
|
}, [note]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user