From 93866e56d2f532edacf9bc8caeabb98c6a2e3c1f Mon Sep 17 00:00:00 2001 From: DiamondThree <857159145@qq.com> Date: Mon, 9 Jan 2023 20:35:12 +0800 Subject: [PATCH] feat: active workspace when created workspace --- .../src/components/create-workspace/index.tsx | 5 +- .../src/components/workspace-modal/index.tsx | 57 +++++++++++-------- .../WorkspaceSelector/WorkspaceSelector.tsx | 1 - 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/packages/app/src/components/create-workspace/index.tsx b/packages/app/src/components/create-workspace/index.tsx index c1abd2cbc..dc7d245fb 100644 --- a/packages/app/src/components/create-workspace/index.tsx +++ b/packages/app/src/components/create-workspace/index.tsx @@ -7,6 +7,7 @@ import { KeyboardEvent } from 'react'; import { useTranslation } from 'react-i18next'; import { useAppState } from '@/providers/app-state-provider'; import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; +import { useRouter } from 'next/router'; interface ModalProps { open: boolean; @@ -16,11 +17,11 @@ interface ModalProps { export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => { const [workspaceName, setWorkspaceName] = useState(''); const { createWorkspace } = useWorkspaceHelper(); - const { loadWorkspace } = useAppState(); + const router = useRouter(); const handleCreateWorkspace = async () => { const workspace = await createWorkspace(workspaceName); if (workspace && workspace.room) { - await loadWorkspace(workspace.room); + router.replace(`/workspace/${workspace.room}`); onClose(); } else { console.log('create error'); diff --git a/packages/app/src/components/workspace-modal/index.tsx b/packages/app/src/components/workspace-modal/index.tsx index c5c9c4b8f..6747e58da 100644 --- a/packages/app/src/components/workspace-modal/index.tsx +++ b/packages/app/src/components/workspace-modal/index.tsx @@ -24,7 +24,7 @@ interface WorkspaceModalProps { export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => { const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false); const { confirm } = useConfirm(); - const { user, workspaceList } = useAppState(); + const { user, workspaceList, currentWorkspace } = useAppState(); const router = useRouter(); return (
@@ -53,6 +53,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => { router.replace(`/workspace/${item.id}`); onClose(); }} + active={item.id === currentWorkspace.room} key={index} > @@ -152,23 +153,23 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => { onClose={() => { setCreateWorkspaceOpen(false); onClose(); - confirm({ - title: 'Enable AFFiNE Cloud?', - content: `If enabled, the data in this workspace will be backed up and synchronized via AFFiNE Cloud.`, - confirmText: user ? 'Enable' : 'Sign in and Enable', - cancelText: 'Skip', - }).then(confirm => { - if (confirm) { - if (user) { - // workspaceId && - // updateWorkspaceMeta(workspaceId, { isPublish: true }); - } else { - // login(); - // workspaceId && - // updateWorkspaceMeta(workspaceId, { isPublish: true }); - } - } - }); + // confirm({ + // title: 'Enable AFFiNE Cloud?', + // content: `If enabled, the data in this workspace will be backed up and synchronized via AFFiNE Cloud.`, + // confirmText: user ? 'Enable' : 'Sign in and Enable', + // cancelText: 'Skip', + // }).then(confirm => { + // if (confirm) { + // if (user) { + // // workspaceId && + // // updateWorkspaceMeta(workspaceId, { isPublish: true }); + // } else { + // // login(); + // // workspaceId && + // // updateWorkspaceMeta(workspaceId, { isPublish: true }); + // } + // } + // }); }} > @@ -213,11 +214,17 @@ const WorkspaceList = styled('div')({ gridTemplateColumns: 'repeat(2, 1fr)', }); -const WorkspaceItem = styled('div')({ - cursor: 'pointer', - padding: '8px', - border: '1px solid #eee', - ':hover': { - background: '#eee', - }, +export const WorkspaceItem = styled.div<{ + active: boolean; +}>(({ theme, active }) => { + const backgroundColor = active ? theme.colors.hoverBackground : 'transparent'; + return { + cursor: 'pointer', + padding: '8px', + border: '1px solid #eee', + backgroundColor: backgroundColor, + ':hover': { + background: theme.colors.hoverBackground, + }, + }; }); diff --git a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx index f829f3c89..1b5995b69 100644 --- a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx +++ b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx @@ -15,7 +15,6 @@ export const WorkspaceSelector = () => { return ( <> -
{currentWorkspace.meta.name}
{ setWorkspaceListShow(true);