From c903b3adaad44ea1c9ac036664ab5c7956b82bef Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 9 Feb 2022 17:48:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0pin=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?useCurrentGroupPanelInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/model/group.ts | 1 + shared/redux/slices/group.ts | 33 ++++++++ web/plugins/com.msgbyte.webview/src/index.tsx | 11 +-- .../components/Panel/group/PluginPanel.tsx | 2 +- web/src/plugin/common/index.ts | 5 +- web/src/plugin/common/reg.ts | 3 +- web/src/routes/Main/Content/Group/Panel.tsx | 77 +++++++++++-------- .../routes/Main/Content/Group/SidebarItem.tsx | 46 ++++++++++- web/src/routes/Main/Content/Group/index.tsx | 50 ++++++++---- web/src/routes/Main/Content/Group/utils.ts | 7 -- 10 files changed, 171 insertions(+), 64 deletions(-) diff --git a/shared/model/group.ts b/shared/model/group.ts index 2396f05f..9e16bf2f 100644 --- a/shared/model/group.ts +++ b/shared/model/group.ts @@ -28,6 +28,7 @@ export interface GroupInfo { owner: string; members: GroupMember[]; panels: GroupPanel[]; + pinnedPanelId?: string; // 被钉选的面板Id } /** diff --git a/shared/redux/slices/group.ts b/shared/redux/slices/group.ts index a0fd1e4e..7f5d9472 100644 --- a/shared/redux/slices/group.ts +++ b/shared/redux/slices/group.ts @@ -42,6 +42,39 @@ const groupSlice = createSlice({ const groupId = action.payload; delete state.groups[groupId]; }, + pinGroupPanel( + state, + action: PayloadAction<{ + groupId: string; + panelId: string; + }> + ) { + const { groupId, panelId } = action.payload; + + if (state.groups[groupId]) { + // NOTICE: updateGroup 只会去更新,不会去添加新的 + state.groups[groupId] = { + ...state.groups[groupId], + pinnedPanelId: panelId, + }; + } + }, + unpinGroupPanel( + state, + action: PayloadAction<{ + groupId: string; + }> + ) { + const { groupId } = action.payload; + + if (state.groups[groupId]) { + // NOTICE: updateGroup 只会去更新,不会去添加新的 + state.groups[groupId] = { + ...state.groups[groupId], + pinnedPanelId: undefined, + }; + } + }, }, }); diff --git a/web/plugins/com.msgbyte.webview/src/index.tsx b/web/plugins/com.msgbyte.webview/src/index.tsx index 72058c60..0776c20b 100644 --- a/web/plugins/com.msgbyte.webview/src/index.tsx +++ b/web/plugins/com.msgbyte.webview/src/index.tsx @@ -1,17 +1,18 @@ import React from 'react'; -import { regGroupPanel, useCurrentGroupPanelInfo } from '@capital/common'; +import { regGroupPanel } from '@capital/common'; import { Translate } from './translate'; +import _get from 'lodash/get'; const PLUGIN_NAME = 'com.msgbyte.webview'; -const GroupWebPanelRender = () => { - const groupPanelInfo = useCurrentGroupPanelInfo(); +const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { + const panelInfo = props.panelInfo; - if (!groupPanelInfo) { + if (!panelInfo) { return
{Translate.notfound}
; } - const url = groupPanelInfo.meta?.url; + const url = _get(panelInfo, 'meta.url'); return (