mirror of
https://github.com/zadam/trilium.git
synced 2025-12-12 02:14:25 +01:00
feat(tab_navigation): hide buttons if launcher ones are used
This commit is contained in:
parent
9e094f1d96
commit
82d97ef26f
@ -6,28 +6,31 @@ import { t } from "../services/i18n";
|
|||||||
import { dynamicRequire } from "../services/utils";
|
import { dynamicRequire } from "../services/utils";
|
||||||
import { handleHistoryContextMenu } from "./launch_bar/HistoryNavigation";
|
import { handleHistoryContextMenu } from "./launch_bar/HistoryNavigation";
|
||||||
import ActionButton from "./react/ActionButton";
|
import ActionButton from "./react/ActionButton";
|
||||||
|
import { useLauncherVisibility } from "./react/hooks";
|
||||||
|
|
||||||
export default function TabHistoryNavigationButtons() {
|
export default function TabHistoryNavigationButtons() {
|
||||||
const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []);
|
const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []);
|
||||||
const onContextMenu = handleHistoryContextMenu(webContents);
|
const onContextMenu = handleHistoryContextMenu(webContents);
|
||||||
const { canGoBack, canGoForward } = useBackForwardState(webContents);
|
const { canGoBack, canGoForward } = useBackForwardState(webContents);
|
||||||
|
const legacyBackVisible = useLauncherVisibility("_lbBackInHistory");
|
||||||
|
const legacyForwardVisible = useLauncherVisibility("_lbForwardInHistory");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="tab-history-navigation-buttons">
|
<div className="tab-history-navigation-buttons">
|
||||||
<ActionButton
|
{!legacyBackVisible && <ActionButton
|
||||||
icon="bx bx-left-arrow-alt"
|
icon="bx bx-left-arrow-alt"
|
||||||
text={t("tab_history_navigation_buttons.go-back")}
|
text={t("tab_history_navigation_buttons.go-back")}
|
||||||
triggerCommand="backInNoteHistory"
|
triggerCommand="backInNoteHistory"
|
||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
disabled={!canGoBack}
|
disabled={!canGoBack}
|
||||||
/>
|
/>}
|
||||||
<ActionButton
|
{!legacyForwardVisible && <ActionButton
|
||||||
icon="bx bx-right-arrow-alt"
|
icon="bx bx-right-arrow-alt"
|
||||||
text={t("tab_history_navigation_buttons.go-forward")}
|
text={t("tab_history_navigation_buttons.go-forward")}
|
||||||
triggerCommand="forwardInNoteHistory"
|
triggerCommand="forwardInNoteHistory"
|
||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
disabled={!canGoForward}
|
disabled={!canGoForward}
|
||||||
/>
|
/>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -901,3 +901,29 @@ export function useChildNotes(parentNoteId: string | undefined) {
|
|||||||
|
|
||||||
return childNotes;
|
return childNotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useLauncherVisibility(launchNoteId: string) {
|
||||||
|
const note = froca.getNoteFromCache(launchNoteId);
|
||||||
|
const [ isVisible, setIsVisible ] = useState<boolean>(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;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user