feat: active workspace when created workspace

This commit is contained in:
DiamondThree
2023-01-09 20:35:12 +08:00
parent 9ef0fe9d06
commit 93866e56d2
3 changed files with 35 additions and 28 deletions

View File

@@ -7,6 +7,7 @@ import { KeyboardEvent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useAppState } from '@/providers/app-state-provider'; import { useAppState } from '@/providers/app-state-provider';
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
import { useRouter } from 'next/router';
interface ModalProps { interface ModalProps {
open: boolean; open: boolean;
@@ -16,11 +17,11 @@ interface ModalProps {
export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => { export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
const [workspaceName, setWorkspaceName] = useState(''); const [workspaceName, setWorkspaceName] = useState('');
const { createWorkspace } = useWorkspaceHelper(); const { createWorkspace } = useWorkspaceHelper();
const { loadWorkspace } = useAppState(); const router = useRouter();
const handleCreateWorkspace = async () => { const handleCreateWorkspace = async () => {
const workspace = await createWorkspace(workspaceName); const workspace = await createWorkspace(workspaceName);
if (workspace && workspace.room) { if (workspace && workspace.room) {
await loadWorkspace(workspace.room); router.replace(`/workspace/${workspace.room}`);
onClose(); onClose();
} else { } else {
console.log('create error'); console.log('create error');

View File

@@ -24,7 +24,7 @@ interface WorkspaceModalProps {
export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => { export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false); const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
const { confirm } = useConfirm(); const { confirm } = useConfirm();
const { user, workspaceList } = useAppState(); const { user, workspaceList, currentWorkspace } = useAppState();
const router = useRouter(); const router = useRouter();
return ( return (
<div> <div>
@@ -53,6 +53,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
router.replace(`/workspace/${item.id}`); router.replace(`/workspace/${item.id}`);
onClose(); onClose();
}} }}
active={item.id === currentWorkspace.room}
key={index} key={index}
> >
<span style={{ width: '100px' }}> <span style={{ width: '100px' }}>
@@ -152,23 +153,23 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
onClose={() => { onClose={() => {
setCreateWorkspaceOpen(false); setCreateWorkspaceOpen(false);
onClose(); onClose();
confirm({ // confirm({
title: 'Enable AFFiNE Cloud?', // title: 'Enable AFFiNE Cloud?',
content: `If enabled, the data in this workspace will be backed up and synchronized via 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', // confirmText: user ? 'Enable' : 'Sign in and Enable',
cancelText: 'Skip', // cancelText: 'Skip',
}).then(confirm => { // }).then(confirm => {
if (confirm) { // if (confirm) {
if (user) { // if (user) {
// workspaceId && // // workspaceId &&
// updateWorkspaceMeta(workspaceId, { isPublish: true }); // // updateWorkspaceMeta(workspaceId, { isPublish: true });
} else { // } else {
// login(); // // login();
// workspaceId && // // workspaceId &&
// updateWorkspaceMeta(workspaceId, { isPublish: true }); // // updateWorkspaceMeta(workspaceId, { isPublish: true });
} // }
} // }
}); // });
}} }}
></CreateWorkspaceModal> ></CreateWorkspaceModal>
</ModalWrapper> </ModalWrapper>
@@ -213,11 +214,17 @@ const WorkspaceList = styled('div')({
gridTemplateColumns: 'repeat(2, 1fr)', gridTemplateColumns: 'repeat(2, 1fr)',
}); });
const WorkspaceItem = styled('div')({ export const WorkspaceItem = styled.div<{
cursor: 'pointer', active: boolean;
padding: '8px', }>(({ theme, active }) => {
border: '1px solid #eee', const backgroundColor = active ? theme.colors.hoverBackground : 'transparent';
':hover': { return {
background: '#eee', cursor: 'pointer',
}, padding: '8px',
border: '1px solid #eee',
backgroundColor: backgroundColor,
':hover': {
background: theme.colors.hoverBackground,
},
};
}); });

View File

@@ -15,7 +15,6 @@ export const WorkspaceSelector = () => {
return ( return (
<> <>
<div>{currentWorkspace.meta.name}</div>
<SelectorWrapper <SelectorWrapper
onClick={() => { onClick={() => {
setWorkspaceListShow(true); setWorkspaceListShow(true);