mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
use search results for state
This commit is contained in:
parent
9d0b532aeb
commit
921b56a89e
@ -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, useRef, useState } from "preact/hooks";
|
import { useContext, useEffect, 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";
|
||||||
@ -26,7 +26,6 @@ export default function SearchDefinitionTab({ note, ntxId, hidden }: TabContext)
|
|||||||
const parentComponent = useContext(ParentComponent);
|
const parentComponent = useContext(ParentComponent);
|
||||||
const [ searchOptions, setSearchOptions ] = useState<{ availableOptions: SearchOption[], activeOptions: SearchOption[] }>();
|
const [ searchOptions, setSearchOptions ] = useState<{ availableOptions: SearchOption[], activeOptions: SearchOption[] }>();
|
||||||
const [ error, setError ] = useState<{ message: string }>();
|
const [ error, setError ] = useState<{ message: string }>();
|
||||||
const autoExecutedRef = useRef<string | null>(null);
|
|
||||||
|
|
||||||
function refreshOptions() {
|
function refreshOptions() {
|
||||||
if (!note) return;
|
if (!note) return;
|
||||||
@ -76,18 +75,25 @@ export default function SearchDefinitionTab({ note, ntxId, hidden }: TabContext)
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function autoExecute() {
|
async function autoExecute() {
|
||||||
console.log('Effect running, noteId:', note?.noteId, 'ref:', autoExecutedRef.current);
|
if (!note?.hasLabel('autoExecuteSearch')) {
|
||||||
if (autoExecutedRef.current !== note?.noteId && note?.hasLabel("autoExecuteSearch")) {
|
return;
|
||||||
console.log('Setting ref to:', note.noteId);
|
}
|
||||||
autoExecutedRef.current = note.noteId;
|
|
||||||
console.log('Ref after setting:', autoExecutedRef.current);
|
console.log('Executing search');
|
||||||
await refreshResults();
|
|
||||||
parentComponent?.triggerCommand("toggleRibbonTabBookProperties", {});
|
// Only execute if no results exist yet
|
||||||
|
await refreshResults();
|
||||||
|
|
||||||
|
console.log('Executed search');
|
||||||
|
|
||||||
|
const hasResults = note.children && note.children.length > 0;
|
||||||
|
|
||||||
|
if (hasResults) {
|
||||||
|
parentComponent?.triggerCommand('toggleRibbonTabBookProperties', { ntxId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
autoExecute();
|
autoExecute();
|
||||||
}, [note?.noteId]);
|
}, [note]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="search-definition-widget">
|
<div className="search-definition-widget">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user