Files
outline/app/hooks/useSyncSidebarContext.ts
Tom MoorandClaude Opus 5.5 5647621224 chore: Prune redundant comments and type suppressions (#14124)
* chore: Prune redundant comments and normalize lint directives

Removes comments that restate the following line and stale TODOs, drops
the passive event listener feature check now that all supported browsers
support it, and renames eslint directives to oxlint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH

* fix: Evaluate restricted team domains at validation time

The restricted email provider list was captured when the model loaded, so
it could not follow the hosting environment and the tests that covered it
never reached the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH

* chore: Replace type suppressions with accurate types

Adds a Concrete helper type for registries of abstract classes, declares
missing Sequelize and refractor typings, uses public ProseMirror APIs, a
typed mock context helper in middleware tests, and a StaticLink component
for sidebar rows being edited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-17 17:07:39 -04:00

54 lines
1.9 KiB
TypeScript

import { useEffect } from "react";
import { useHistory } from "react-router-dom";
import type { SidebarContextType } from "~/components/Sidebar/components/SidebarContext";
import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext";
import useStores from "~/hooks/useStores";
import { patchLocation } from "~/utils/history";
/**
* Writes the sidebar context of the active document into the location state, so
* that the section which contains the document is the one revealed in the
* sidebar. Sections the user is already looking at, and the starred section,
* are left alone.
*
* @param belongsToSection whether the given context is one of this section's own.
* @param resolve returns the context for the active document, or undefined when
* the document does not belong to this section.
*/
export function useSyncSidebarContext(
belongsToSection: (context: NonNullable<SidebarContextType>) => boolean,
resolve: (activeDocumentId: string) => SidebarContextType | undefined
) {
const { ui } = useStores();
const history = useHistory();
const locationSidebarContext = useLocationSidebarContext();
useEffect(() => {
if (
!ui.activeDocumentId ||
(locationSidebarContext &&
(belongsToSection(locationSidebarContext) ||
locationSidebarContext.startsWith("starred")))
) {
return;
}
const sidebarContext = resolve(ui.activeDocumentId);
if (!sidebarContext) {
return;
}
history.push(
patchLocation(history.location, {
state: {
...(history.location.state as Record<string, unknown>),
sidebarContext,
},
})
);
// `history` is read imperatively, the sidebar context should only be
// recalculated when the active document or memberships change.
// oxlint-disable-next-line react-hooks/exhaustive-deps
}, [ui.activeDocumentId, locationSidebarContext, belongsToSection, resolve]);
}