diff --git a/apps/client/src/widgets/TabHistoryNavigationButtons.tsx b/apps/client/src/widgets/TabHistoryNavigationButtons.tsx index 76fa80b6e..142f4c7bb 100644 --- a/apps/client/src/widgets/TabHistoryNavigationButtons.tsx +++ b/apps/client/src/widgets/TabHistoryNavigationButtons.tsx @@ -6,28 +6,31 @@ import { t } from "../services/i18n"; import { dynamicRequire } from "../services/utils"; import { handleHistoryContextMenu } from "./launch_bar/HistoryNavigation"; import ActionButton from "./react/ActionButton"; +import { useLauncherVisibility } from "./react/hooks"; export default function TabHistoryNavigationButtons() { const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []); const onContextMenu = handleHistoryContextMenu(webContents); const { canGoBack, canGoForward } = useBackForwardState(webContents); + const legacyBackVisible = useLauncherVisibility("_lbBackInHistory"); + const legacyForwardVisible = useLauncherVisibility("_lbForwardInHistory"); return (
- - } + {!legacyForwardVisible && + />}
); } diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 0c9883df2..bd1085e4e 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -901,3 +901,29 @@ export function useChildNotes(parentNoteId: string | undefined) { return childNotes; } + +export function useLauncherVisibility(launchNoteId: string) { + const note = froca.getNoteFromCache(launchNoteId); + const [ isVisible, setIsVisible ] = useState(checkIfVisible(note)); + + // React to note not being available in the cache. + useEffect(() => { + if (!note) return; + froca.getNote(launchNoteId).then(fetchedNote => setIsVisible(checkIfVisible(fetchedNote))); + }, [ note, launchNoteId ]); + + // React to changes. + useTriliumEvent("entitiesReloaded", ({ loadResults }) => { + if (!note) return; + if (loadResults.getBranchRows().some(branch => branch.noteId === launchNoteId)) { + setIsVisible(checkIfVisible(note)); + } + }); + + function checkIfVisible(note: FNote | undefined | null) { + return note?.getParentBranches().some(branch => + [ "_lbVisibleLaunchers", "_lbMobileVisibleLaunchers" ].includes(branch.parentNoteId)) ?? false; + } + + return isVisible; +}