MCPcopy Create free account
hub / github.com/msgbyte/tailchat / usePanelWindow

Function usePanelWindow

client/web/src/hooks/usePanelWindow.ts:9–39  ·  view source on GitHub ↗
(panelUrl: string)

Source from the content-addressed store, hash-verified

7 * 使用hooks来将 redux 数据与 panelWindowManager 数据联合
8 */
9export function usePanelWindow(panelUrl: string) {
10 const hasOpenedPanel = useAppSelector(
11 (state) =>
12 /**
13 * 两处维护地址均存在才视为在控制下
14 */
15 state.ui.panelWinUrls.includes(panelUrl) &&
16 panelWindowManager.has(panelUrl)
17 );
18 const dispatch = useAppDispatch();
19
20 const openPanelWindow = useCallback(() => {
21 panelWindowManager.open(panelUrl, {
22 onClose() {
23 dispatch(uiActions.deletePanelWindowUrl({ url: panelUrl }));
24 },
25 });
26 dispatch(uiActions.addPanelWindowUrl({ url: panelUrl }));
27 }, [panelUrl]);
28
29 const closePanelWindow = useCallback(() => {
30 panelWindowManager.close(panelUrl);
31 dispatch(uiActions.deletePanelWindowUrl({ url: panelUrl }));
32 }, [panelUrl]);
33
34 return {
35 hasOpenedPanel,
36 openPanelWindow,
37 closePanelWindow,
38 };
39}

Callers 3

ConversePanel.tsxFile · 0.90
SidebarItem.tsxFile · 0.90

Calls 4

useAppSelectorFunction · 0.85
hasMethod · 0.80
openMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected