From 84b62e474afebeba0b72f66bc1014e574f9675dd Mon Sep 17 00:00:00 2001 From: DiamondThree <857159145@qq.com> Date: Tue, 10 Jan 2023 14:12:24 +0800 Subject: [PATCH] feat: add updateWorkspace function --- .../workspace-setting/general/General.tsx | 21 +++++-------------- .../app/src/hooks/use-workspace-helper.ts | 15 ++++++++++--- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/app/src/components/workspace-setting/general/General.tsx b/packages/app/src/components/workspace-setting/general/General.tsx index dd342d79a4..a424685e97 100644 --- a/packages/app/src/components/workspace-setting/general/General.tsx +++ b/packages/app/src/components/workspace-setting/general/General.tsx @@ -15,11 +15,14 @@ import { WorkspaceLeave } from './leave'; import { Upload } from '@/components/file-upload'; import { WorkspaceAvatar } from '@/components/workspace-avatar'; import { WorkspaceInfo } from '@affine/datacenter'; +import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; export const GeneralPage = ({ workspace }: { workspace: WorkspaceInfo }) => { const [showDelete, setShowDelete] = useState(false); const [showLeave, setShowLeave] = useState(false); const [uploading, setUploading] = useState(false); const [workspaceName, setWorkspaceName] = useState(workspace.name); + const { currentWorkspace } = useAppState(); + const { updateWorkspace } = useWorkspaceHelper(); const isOwner = true; const handleChangeWorkSpaceName = (newName: string) => { setWorkspaceName(newName); @@ -38,6 +41,8 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceInfo }) => { setShowLeave(false); }; const handleUpdateWorkspaceName = () => { + console.log('currentWorkspace: ', currentWorkspace); + updateWorkspace({ name: workspaceName }, currentWorkspace); // workspace && currentWorkspace(workspace.id, { name: workspaceName }); }; @@ -97,22 +102,6 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceInfo }) => { ✔️ - {/* {userInfo ? ( -
- Workspace Owner - - - -
- ) : ( - '' - )} */} - Workspace Type {workspace.provider} diff --git a/packages/app/src/hooks/use-workspace-helper.ts b/packages/app/src/hooks/use-workspace-helper.ts index 4a396074d4..5b49a8b1e5 100644 --- a/packages/app/src/hooks/use-workspace-helper.ts +++ b/packages/app/src/hooks/use-workspace-helper.ts @@ -1,6 +1,7 @@ import { useAppState } from '@/providers/app-state-provider'; +import { stringToColour } from '@/utils'; import { WorkspaceInfo } from '@affine/datacenter'; - +import { Workspace } from '@blocksuite/store'; export const useWorkspaceHelper = () => { const { dataCenter } = useAppState(); const createWorkspace = async (name: string) => { @@ -21,8 +22,16 @@ export const useWorkspaceHelper = () => { dataCenter.setWorkspacePublish(workspaceId, publish); }; - const updateWorkspace = async (workspace: WorkspaceInfo) => { - console.log('workspace: ', workspace); + const updateWorkspace = async ( + { name, avatar }: { name?: string; avatar?: string }, + workspace: Workspace + ) => { + if (name) { + dataCenter.resetWorkspaceMeta({ name }, workspace); + } + // if (avatar) { + // dataCenter.resetWorkspaceMeta({ avatar }, workspace); + // } }; return { createWorkspace,