Add a setting to leave unused integration pages out of the menu

Settings -> Display -> Menu: when on, the menu, command palette and shortcuts
omit the pages of integration kinds nobody has added (off by default, the same
for everyone). Pages useful without an integration always stay; adding an
integration brings its page back at once.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-08 22:11:05 +01:00
1 parent 8f5068c6e0
commit 587e8856a0
13 files changed
+346 -7

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { useEffect, useSyncExternalStore } from "react";
import { api } from "../api/client";
import { getHiddenPages, setHiddenPages, subscribeHiddenPages, unusedPages } from "../utils/navVisibility";
/** Said by the pages that change what the menu depends on (adding or removing an integration, the Display setting), so it is worked out again at once. */
export const MENU_CHANGED = "menu-changed";
/** Which pages the menu leaves out, as a set that changes when it does — for a component that draws or lists the menu. */
export function useHiddenPages(): ReadonlySet<string> {
return useSyncExternalStore(subscribeHiddenPages, getHiddenPages, getHiddenPages);
}
/**
* Keeps the menu's hidden pages up to date: if the Display setting asks for pages of integrations nobody has added to be left out, they are; otherwise nothing is.
* Used once, by the shell. When it cannot find out (offline, an error) it leaves the menu as it was — never hiding a page on a guess.
*/
export function useMenuHiding(): void {
useEffect(() => {
let cancelled = false;
const load = () =>
Promise.all([api.settings.display(), api.integrations.list()])
.then(([d, i]) => {
if (!cancelled) setHiddenPages(d.display.hideUnusedPages ? unusedPages(i.integrations.map((x) => x.type)) : []);
})
.catch(() => {});
void load();
const timer = setInterval(load, 5 * 60_000);
window.addEventListener(MENU_CHANGED, load);
return () => {
cancelled = true;
clearInterval(timer);
window.removeEventListener(MENU_CHANGED, load);
};
}, []);
}
+3 -1
View File
@@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom";
import type { CurrentUser } from "../api/client";
import { visibleNav, isGroup } from "../layout/nav";
import { GO_SHORTCUTS, SHOW_SHORTCUTS_EVENT } from "../layout/shortcuts";
import { useHiddenPages } from "./useMenuHiding";
/** Whether the keyboard is typing into something, in which case a letter is a letter and not a shortcut. */
function isTyping(target: EventTarget | null): boolean {
@@ -18,6 +19,7 @@ function isTyping(target: EventTarget | null): boolean {
*/
export function useShortcuts(user: CurrentUser): void {
const navigate = useNavigate();
const hiddenPages = useHiddenPages();
useEffect(() => {
const allowed = new Set<string>(["/", "/wall"]);
@@ -80,5 +82,5 @@ export function useShortcuts(user: CurrentUser): void {
window.removeEventListener("keydown", onKeyDown);
reset();
};
}, [user.role, navigate]);
}, [user.role, navigate, hiddenPages]);
}