chore(tab_navigation): address requested changes

This commit is contained in:
Elian Doran 2025-12-09 16:02:24 +02:00
parent 7da9367dc9
commit cda39e967c
No known key found for this signature in database

View File

@ -903,27 +903,25 @@ export function useChildNotes(parentNoteId: string | undefined) {
}
export function useLauncherVisibility(launchNoteId: string) {
const checkIfVisible = useCallback(() => {
const note = froca.getNoteFromCache(launchNoteId);
const [ isVisible, setIsVisible ] = useState<boolean>(checkIfVisible(note));
return note?.getParentBranches().some(branch =>
[ "_lbVisibleLaunchers", "_lbMobileVisibleLaunchers" ].includes(branch.parentNoteId)) ?? false;
}, [ launchNoteId ]);
const [ isVisible, setIsVisible ] = useState<boolean>(checkIfVisible());
// React to note not being available in the cache.
useEffect(() => {
if (!note) return;
froca.getNote(launchNoteId).then(fetchedNote => setIsVisible(checkIfVisible(fetchedNote)));
}, [ note, launchNoteId ]);
froca.getNote(launchNoteId).then(() => setIsVisible(checkIfVisible()));
}, [ launchNoteId, checkIfVisible ]);
// React to changes.
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
if (!note) return;
if (loadResults.getBranchRows().some(branch => branch.noteId === launchNoteId)) {
setIsVisible(checkIfVisible(note));
setIsVisible(checkIfVisible());
}
});
function checkIfVisible(note: FNote | undefined | null) {
return note?.getParentBranches().some(branch =>
[ "_lbVisibleLaunchers", "_lbMobileVisibleLaunchers" ].includes(branch.parentNoteId)) ?? false;
}
return isVisible;
}