The 43 react-refresh/only-export-components warnings the gate let through meant an edit to a provider (or AnchoredPopover, Toaster, plexDetailUi, …) could not be hot-swapped: Fast Refresh reloads a module that also exports hooks or helpers. - Each provider's contexts, the types its hooks return and the hooks themselves live in a sibling context module (navigationContext.ts, channelsContext.ts, …); the provider file keeps the component. loadAccountFilters moved next to the feed filters' defaults (feedFiltersInit.ts), following navigationInit/playlistsInit. - Helpers that sat in component files have their own modules: welcomeMode, downloadTitle, plexPlayable, channelSync, ui/anchoredPopoverHooks, ui/pageToolbarSlot, ui/pagerContent, ui/toastLevels, ui/overlayOrder, ui/tableAlign, lib/plexDetail; the cells of the channel columns and the registry's page wrappers are components files of their own (channelCells, modulePages). - usePersistedTab, an alias of useAccountPersistedState, is gone; its callers use the original. npm run lint is now eslint --max-warnings 0, so a warning fails the gate like an error does.
74 lines
3.0 KiB
TypeScript
74 lines
3.0 KiB
TypeScript
import { createContext, useContext } from "react";
|
|
import type { ChannelLayout } from "../lib/channelLayout";
|
|
import type { SortState } from "../lib/columnSort";
|
|
import type { FilterMap } from "../lib/tableColumns";
|
|
import type { ChannelsView } from "./Channels";
|
|
|
|
// The Channels module's contexts + hooks, split out of ChannelsProvider so that file exports only
|
|
// components (Fast Refresh). The provider owns the state; this is the read side every consumer imports.
|
|
|
|
export type ChannelsState = {
|
|
search: string;
|
|
// The subscribed table's column filters, lifted out of DataTable so the top status chips, the Sync
|
|
// column funnel, and the card layout share ONE filter state (the sync chip lives at `filters.sync`).
|
|
filters: FilterMap;
|
|
view: ChannelsView;
|
|
// The subscribed table's sort, lifted out of DataTable so the card layout shares it.
|
|
sort: SortState;
|
|
// Bumped to tell the manager to drop a stale column filter when an intent sends the user to a
|
|
// specific set (the header's "without full history" link).
|
|
filtersResetToken: number;
|
|
focusName: string | null;
|
|
// Bumped every time a focus intent is (re-)issued, so re-focusing the same channel re-seeds the
|
|
// manager's name filter even when the name is unchanged.
|
|
focusToken: number;
|
|
};
|
|
|
|
export interface ChannelsActions {
|
|
setSearch: (q: string) => void;
|
|
setFilters: (f: FilterMap) => void;
|
|
setView: (v: ChannelsView) => void;
|
|
setLayout: (l: ChannelLayout) => void;
|
|
setSort: (s: SortState) => void;
|
|
// "Focus this channel in the manager": jump to Channels (subscriptions tab) and seed its name
|
|
// filter so the channel is isolated. Called from the feed sidebar and the notifications inbox.
|
|
focusChannel: (name: string) => void;
|
|
// Jump to the manager filtered to channels still missing full history (the header sync chip).
|
|
goToFullHistory: () => void;
|
|
}
|
|
|
|
export const ChannelsStateContext = createContext<ChannelsState>({
|
|
search: "",
|
|
filters: {},
|
|
view: "subscribed",
|
|
sort: null,
|
|
filtersResetToken: 0,
|
|
focusName: null,
|
|
focusToken: 0,
|
|
});
|
|
// The table/cards density gets its OWN context, deliberately narrow: App reads it (to decide the
|
|
// shell's top fade) and would otherwise re-render the whole app on every keystroke in the manager's
|
|
// search box, since the state context above changes with it.
|
|
export const ChannelLayoutContext = createContext<ChannelLayout>("table");
|
|
export const ChannelsActionsContext = createContext<ChannelsActions>({
|
|
setSearch: () => {},
|
|
setFilters: () => {},
|
|
setView: () => {},
|
|
setLayout: () => {},
|
|
setSort: () => {},
|
|
focusChannel: () => {},
|
|
goToFullHistory: () => {},
|
|
});
|
|
|
|
export function useChannels(): ChannelsState {
|
|
return useContext(ChannelsStateContext);
|
|
}
|
|
/** The manager's table/cards density on its own — subscribe to this instead of the whole state when
|
|
* the layout is all you need (App does, for the shell's top fade). */
|
|
export function useChannelLayout(): ChannelLayout {
|
|
return useContext(ChannelLayoutContext);
|
|
}
|
|
export function useChannelsActions(): ChannelsActions {
|
|
return useContext(ChannelsActionsContext);
|
|
}
|