mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08:00
feat: more fluent
This commit is contained in:
@@ -4,16 +4,19 @@ import { Button } from '@/ui/button';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { createWorkspace } from '@/hooks/mock-data/mock';
|
import { createWorkspace } from '@/hooks/mock-data/mock';
|
||||||
import Input from '@/ui/input';
|
import Input from '@/ui/input';
|
||||||
|
interface ICloseParams {
|
||||||
|
workspaceId?: string;
|
||||||
|
}
|
||||||
interface ModalProps {
|
interface ModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: (opts?: ICloseParams) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
||||||
const [workspaceName, setWorkspaceName] = useState('');
|
const [workspaceName, setWorkspaceName] = useState('');
|
||||||
const handleCreateWorkspace = () => {
|
const handleCreateWorkspace = () => {
|
||||||
createWorkspace(workspaceName);
|
const { workspaceId } = createWorkspace(workspaceName);
|
||||||
onClose();
|
onClose({ workspaceId });
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
User,
|
User,
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
SignOut,
|
SignOut,
|
||||||
|
updateWorkspaceMeta,
|
||||||
} from '@/hooks/mock-data/mock';
|
} from '@/hooks/mock-data/mock';
|
||||||
import { CreateWorkspaceModal } from '../create-workspace';
|
import { CreateWorkspaceModal } from '../create-workspace';
|
||||||
import {
|
import {
|
||||||
@@ -102,13 +103,23 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
|
|||||||
fill="#6880FF"
|
fill="#6880FF"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
{item.name}
|
|
||||||
|
<span style={{ width: '100px', display: 'inline-block' }}>
|
||||||
|
{item.name || ' undefined'}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span style={{ position: 'relative', top: '6px' }}>
|
<span
|
||||||
{item.type === 'local' && (
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
top: '6px',
|
||||||
|
marginLeft: '100px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(item.workspaceType === 'local' ||
|
||||||
|
!item.workspaceType) && (
|
||||||
<CloudUnsyncedIcon fontSize={24} />
|
<CloudUnsyncedIcon fontSize={24} />
|
||||||
)}
|
)}
|
||||||
{item.type === 'cloud' && (
|
{item.workspaceType === 'cloud' && (
|
||||||
<CloudInsyncIcon fontSize={24} />
|
<CloudInsyncIcon fontSize={24} />
|
||||||
)}
|
)}
|
||||||
{item.isPublish && <UsersIcon fontSize={24} />}
|
{item.isPublish && <UsersIcon fontSize={24} />}
|
||||||
@@ -165,7 +176,7 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
|
|||||||
</Footer>
|
</Footer>
|
||||||
<CreateWorkspaceModal
|
<CreateWorkspaceModal
|
||||||
open={createWorkspaceOpen}
|
open={createWorkspaceOpen}
|
||||||
onClose={() => {
|
onClose={({ workspaceId }) => {
|
||||||
setCreateWorkspaceOpen(false);
|
setCreateWorkspaceOpen(false);
|
||||||
setList();
|
setList();
|
||||||
onClose();
|
onClose();
|
||||||
@@ -177,6 +188,12 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
|
|||||||
}).then(confirm => {
|
}).then(confirm => {
|
||||||
if (user) {
|
if (user) {
|
||||||
console.log('enable cloud');
|
console.log('enable cloud');
|
||||||
|
workspaceId &&
|
||||||
|
setTimeout(() => {
|
||||||
|
updateWorkspaceMeta(workspaceId as string, {
|
||||||
|
workspaceType: 'cloud',
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
} else {
|
} else {
|
||||||
confirm && Login();
|
confirm && Login();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export interface Workspace {
|
|||||||
isPublish?: boolean; // 是否公开
|
isPublish?: boolean; // 是否公开
|
||||||
isLocal?: boolean; // 是否全部数据都在本地
|
isLocal?: boolean; // 是否全部数据都在本地
|
||||||
avatar?: string; // 封面
|
avatar?: string; // 封面
|
||||||
|
workspaceType: 'local' | 'cloud' | 'join'; // cloud: 云端(本次暂不支持),local: 本地,join : 加入别人的
|
||||||
type: 'local' | 'cloud' | 'join'; // cloud: 云端(本次暂不支持),local: 本地,join : 加入别人的
|
type: 'local' | 'cloud' | 'join'; // cloud: 云端(本次暂不支持),local: 本地,join : 加入别人的
|
||||||
workspaceOwner?: User; // 本地工作空间的拥有者
|
workspaceOwner?: User; // 本地工作空间的拥有者
|
||||||
}
|
}
|
||||||
@@ -40,14 +41,16 @@ export function updateWorkspaceMeta(
|
|||||||
const activeWorkspace = getActiveWorkspace();
|
const activeWorkspace = getActiveWorkspace();
|
||||||
workspaceData.name && (activeWorkspace.name = workspaceData.name);
|
workspaceData.name && (activeWorkspace.name = workspaceData.name);
|
||||||
workspaceData.avatar && (activeWorkspace.avatar = workspaceData.avatar);
|
workspaceData.avatar && (activeWorkspace.avatar = workspaceData.avatar);
|
||||||
|
|
||||||
workspaceData.workspaceType &&
|
workspaceData.workspaceType &&
|
||||||
(activeWorkspace.type = workspaceData.workspaceType);
|
(activeWorkspace.type = workspaceData.workspaceType);
|
||||||
setActiveWorkspace(activeWorkspace);
|
setActiveWorkspace(activeWorkspace);
|
||||||
}
|
}
|
||||||
export function createWorkspace(workspaceName: string) {
|
export function createWorkspace(workspaceName: string) {
|
||||||
|
const workspaceId = 'workspace-' + Date.now();
|
||||||
const workspaceData = {
|
const workspaceData = {
|
||||||
name: workspaceName,
|
name: workspaceName,
|
||||||
id: 'workspace-' + Date.now(),
|
id: workspaceId,
|
||||||
isPublish: false,
|
isPublish: false,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
avatar: '',
|
avatar: '',
|
||||||
@@ -57,6 +60,7 @@ export function createWorkspace(workspaceName: string) {
|
|||||||
workspacesMeta.push(workspaceData);
|
workspacesMeta.push(workspaceData);
|
||||||
localStorage.setItem('affine-workspace', JSON.stringify(workspacesMeta));
|
localStorage.setItem('affine-workspace', JSON.stringify(workspacesMeta));
|
||||||
setActiveWorkspace(workspaceData);
|
setActiveWorkspace(workspaceData);
|
||||||
|
return { workspaceId };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWorkspaces(): Workspace[] {
|
export function getWorkspaces(): Workspace[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user