refactor(nexus): apply Task 6 code-quality fixes to Layout.tsx (phase 8)
Three cleanups from the Task 6 code-quality review: 1. Delete dead instanceSettingsTarget state and supporting code. The useState, the readRememberedInstanceSettingsPath helper, the INSTANCE_SETTINGS_MEMORY_KEY constant, and the localStorage-writing effect were all residue from the old footer sidebar buttons that Task 6 deleted. Verified via grep that no other file in ui/src reads paperclip.lastInstanceSettingsPath. 2. Consolidate two near-identical mobile-nav-visibility effects into one. The standalone isMobile-reset effect was a strict subset of the scroll-listener effect's early-return branch. 3. Drop onToggleSidebar / onTogglePanel stub callbacks. useKeyboardShortcuts declares these as optional and uses optional chaining internally; the stubs were "type contract satisfaction" the contract did not actually require. No behavioral change. 38 frame tests still pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d87f644cde
commit
2dbf281117
1 changed files with 3 additions and 50 deletions
|
|
@ -23,25 +23,10 @@ import { useCompanyPageMemory } from "../hooks/useCompanyPageMemory";
|
||||||
import { healthApi } from "../api/health";
|
import { healthApi } from "../api/health";
|
||||||
import { instanceSettingsApi } from "../api/instanceSettings";
|
import { instanceSettingsApi } from "../api/instanceSettings";
|
||||||
import { shouldSyncCompanySelectionFromRoute } from "../lib/company-selection";
|
import { shouldSyncCompanySelectionFromRoute } from "../lib/company-selection";
|
||||||
import {
|
|
||||||
DEFAULT_INSTANCE_SETTINGS_PATH,
|
|
||||||
normalizeRememberedInstanceSettingsPath,
|
|
||||||
} from "../lib/instance-settings";
|
|
||||||
import { queryKeys } from "../lib/queryKeys";
|
import { queryKeys } from "../lib/queryKeys";
|
||||||
import { cn } from "../lib/utils";
|
import { cn } from "../lib/utils";
|
||||||
import { NotFoundPage } from "../pages/NotFound";
|
import { NotFoundPage } from "../pages/NotFound";
|
||||||
|
|
||||||
const INSTANCE_SETTINGS_MEMORY_KEY = "paperclip.lastInstanceSettingsPath";
|
|
||||||
|
|
||||||
function readRememberedInstanceSettingsPath(): string {
|
|
||||||
if (typeof window === "undefined") return DEFAULT_INSTANCE_SETTINGS_PATH;
|
|
||||||
try {
|
|
||||||
return normalizeRememberedInstanceSettingsPath(window.localStorage.getItem(INSTANCE_SETTINGS_MEMORY_KEY));
|
|
||||||
} catch {
|
|
||||||
return DEFAULT_INSTANCE_SETTINGS_PATH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Layout() {
|
export function Layout() {
|
||||||
const { isMobile } = useSidebar();
|
const { isMobile } = useSidebar();
|
||||||
const { openNewIssue, openOnboarding } = useDialog();
|
const { openNewIssue, openOnboarding } = useDialog();
|
||||||
|
|
@ -59,7 +44,6 @@ export function Layout() {
|
||||||
const onboardingTriggered = useRef(false);
|
const onboardingTriggered = useRef(false);
|
||||||
const lastMainScrollTop = useRef(0);
|
const lastMainScrollTop = useRef(0);
|
||||||
const [mobileNavVisible, setMobileNavVisible] = useState(true);
|
const [mobileNavVisible, setMobileNavVisible] = useState(true);
|
||||||
const [, setInstanceSettingsTarget] = useState<string>(() => readRememberedInstanceSettingsPath());
|
|
||||||
|
|
||||||
const matchedCompany = useMemo(() => {
|
const matchedCompany = useMemo(() => {
|
||||||
if (!companyPrefix) return null;
|
if (!companyPrefix) return null;
|
||||||
|
|
@ -144,13 +128,6 @@ export function Layout() {
|
||||||
useKeyboardShortcuts({
|
useKeyboardShortcuts({
|
||||||
enabled: keyboardShortcutsEnabled,
|
enabled: keyboardShortcutsEnabled,
|
||||||
onNewIssue: () => openNewIssue(),
|
onNewIssue: () => openNewIssue(),
|
||||||
onToggleSidebar: () => {
|
|
||||||
// Phase 8: sidebar toggle is a no-op from keyboard — the rail is fixed.
|
|
||||||
// Kept as a stub so useKeyboardShortcuts' type contract is satisfied.
|
|
||||||
},
|
|
||||||
onTogglePanel: () => {
|
|
||||||
// Phase 8: PropertiesPanel is no longer mounted globally.
|
|
||||||
},
|
|
||||||
onSearch: () => {
|
onSearch: () => {
|
||||||
// Phase 8: open the command palette via synthetic keydown, mirroring
|
// Phase 8: open the command palette via synthetic keydown, mirroring
|
||||||
// the CmdKButton shim. Phase 14 replaces with a real palette context.
|
// the CmdKButton shim. Phase 14 replaces with a real palette context.
|
||||||
|
|
@ -158,15 +135,6 @@ export function Layout() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isMobile) {
|
|
||||||
setMobileNavVisible(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastMainScrollTop.current = 0;
|
|
||||||
setMobileNavVisible(true);
|
|
||||||
}, [isMobile]);
|
|
||||||
|
|
||||||
const updateMobileNavVisibility = useCallback((currentTop: number) => {
|
const updateMobileNavVisibility = useCallback((currentTop: number) => {
|
||||||
const delta = currentTop - lastMainScrollTop.current;
|
const delta = currentTop - lastMainScrollTop.current;
|
||||||
if (currentTop <= 24) setMobileNavVisible(true);
|
if (currentTop <= 24) setMobileNavVisible(true);
|
||||||
|
|
@ -176,11 +144,9 @@ export function Layout() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isMobile) {
|
lastMainScrollTop.current = 0;
|
||||||
setMobileNavVisible(true);
|
setMobileNavVisible(true);
|
||||||
lastMainScrollTop.current = 0;
|
if (!isMobile) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
const onScroll = () => {
|
const onScroll = () => {
|
||||||
updateMobileNavVisibility(window.scrollY || document.documentElement.scrollTop || 0);
|
updateMobileNavVisibility(window.scrollY || document.documentElement.scrollTop || 0);
|
||||||
};
|
};
|
||||||
|
|
@ -197,19 +163,6 @@ export function Layout() {
|
||||||
};
|
};
|
||||||
}, [isMobile]);
|
}, [isMobile]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!location.pathname.startsWith("/instance/settings/")) return;
|
|
||||||
const nextPath = normalizeRememberedInstanceSettingsPath(
|
|
||||||
`${location.pathname}${location.search}${location.hash}`,
|
|
||||||
);
|
|
||||||
setInstanceSettingsTarget(nextPath);
|
|
||||||
try {
|
|
||||||
window.localStorage.setItem(INSTANCE_SETTINGS_MEMORY_KEY, nextPath);
|
|
||||||
} catch {
|
|
||||||
// Ignore storage failures in restricted environments.
|
|
||||||
}
|
|
||||||
}, [location.hash, location.pathname, location.search]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GeneralSettingsProvider value={{ keyboardShortcutsEnabled }}>
|
<GeneralSettingsProvider value={{ keyboardShortcutsEnabled }}>
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue