mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: tho <80c5f18be5aafa62cf6198c6335963ba3306b595288117c8ea2f805fc9bdc94a@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Taylor Ho <taylorkmho@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co> Co-authored-by: tho <80c5f18be5aafa62cf6198c6335963ba3306b595288117c8ea2f805fc9bdc94a@sprout-oss.stage.blox.sqprod.co>
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import * as React from "react";
|
|
|
|
import type { ProfilePanelView } from "@/features/profile/ui/UserProfilePanel";
|
|
import {
|
|
type HistorySearchSetterOptions,
|
|
useHistorySearchState,
|
|
} from "@/shared/hooks/useHistorySearchState";
|
|
|
|
/**
|
|
* Auxiliary-panel state for the channel routes, backed by URL search params
|
|
* via useHistorySearchState: back/forward restores the panel a given entry
|
|
* was showing, and reloads restore the panel from the URL.
|
|
*
|
|
* Params: `thread` (open thread head id), `profile` (profile panel pubkey),
|
|
* `profileView` (profile panel sub-view), `agentSession` (agent session
|
|
* panel pubkey).
|
|
*/
|
|
|
|
export type PanelSetterOptions = HistorySearchSetterOptions;
|
|
|
|
export type PanelValueSetter = (
|
|
value: string | null,
|
|
options?: PanelSetterOptions,
|
|
) => void;
|
|
|
|
const PANEL_SEARCH_KEYS = [
|
|
"agentSession",
|
|
"profile",
|
|
"profileView",
|
|
"thread",
|
|
] as const;
|
|
|
|
function asProfilePanelView(value: string | null): ProfilePanelView {
|
|
return value === "memories" || value === "channels" ? value : "summary";
|
|
}
|
|
|
|
export function useChannelPanelHistoryState() {
|
|
const { applyPatch, values } = useHistorySearchState(PANEL_SEARCH_KEYS);
|
|
|
|
const setOpenThreadHeadId = React.useCallback<PanelValueSetter>(
|
|
(value, options) => applyPatch({ thread: value }, options),
|
|
[applyPatch],
|
|
);
|
|
|
|
// Opening, switching, or closing a profile always resets its sub-view —
|
|
// the carried `profileView` would otherwise leak onto the next profile.
|
|
const setProfilePanelPubkey = React.useCallback<PanelValueSetter>(
|
|
(value, options) =>
|
|
applyPatch({ profile: value, profileView: null }, options),
|
|
[applyPatch],
|
|
);
|
|
|
|
const setProfilePanelView = React.useCallback(
|
|
(value: ProfilePanelView, options?: PanelSetterOptions) =>
|
|
applyPatch({ profileView: value === "summary" ? null : value }, options),
|
|
[applyPatch],
|
|
);
|
|
|
|
const setOpenAgentSessionPubkey = React.useCallback<PanelValueSetter>(
|
|
(value, options) => applyPatch({ agentSession: value }, options),
|
|
[applyPatch],
|
|
);
|
|
|
|
return {
|
|
openAgentSessionPubkey: values.agentSession,
|
|
openThreadHeadId: values.thread,
|
|
profilePanelPubkey: values.profile,
|
|
profilePanelView: asProfilePanelView(values.profileView),
|
|
setOpenAgentSessionPubkey,
|
|
setOpenThreadHeadId,
|
|
setProfilePanelPubkey,
|
|
setProfilePanelView,
|
|
};
|
|
}
|