From dd529f80355aa6134c1ec143f7b60e316ea77587 Mon Sep 17 00:00:00 2001 From: MingLiang Wang Date: Mon, 9 Jan 2023 10:53:18 +0800 Subject: [PATCH] feat: change new data center --- .../src/components/invite-members/index.tsx | 46 ++-- .../login-modal/LoginOptionButton.tsx | 16 +- .../general/delete/delete.tsx | 10 +- .../workspace-setting/general/general.tsx | 26 +-- .../workspace-setting/general/leave/leave.tsx | 4 +- .../workspace-setting/workspace-setting.tsx | 68 +++--- .../SelectorPopperContent.tsx | 6 +- .../workspace-create/workspace-create.tsx | 42 ++-- .../app/src/pages/invite/[invite_code].tsx | 26 +-- .../src/provider/affine/apis/business.ts | 198 ------------------ 10 files changed, 122 insertions(+), 320 deletions(-) delete mode 100644 packages/data-center/src/provider/affine/apis/business.ts diff --git a/packages/app/src/components/invite-members/index.tsx b/packages/app/src/components/invite-members/index.tsx index f06674cb6b..22a72220ee 100644 --- a/packages/app/src/components/invite-members/index.tsx +++ b/packages/app/src/components/invite-members/index.tsx @@ -60,19 +60,19 @@ export const InviteMembers = ({ setShowTip(false); debounce( () => { - getDataCenter() - .then(dc => - dc.apis.getUserByEmail({ - email: value, - workspace_id: workspaceId, - }) - ) - .then(data => { - if (data?.name) { - setUserData(data); - setShowTip(false); - } - }); + // getDataCenter() + // .then(dc => + // dc.apis.getUserByEmail({ + // email: value, + // workspace_id: workspaceId, + // }) + // ) + // .then(data => { + // if (data?.name) { + // setUserData(data); + // setShowTip(false); + // } + // }); }, 300, true @@ -134,16 +134,16 @@ export const InviteMembers = ({ shape="circle" type="primary" onClick={() => { - getDataCenter() - .then(dc => dc.apis.inviteMember({ id: workspaceId, email })) - .then(() => { - onClose(); - onInviteSuccess && onInviteSuccess(); - }) - .catch(err => { - // toast('Invite failed'); - console.log(err); - }); + // getDataCenter() + // .then(dc => dc.apis.inviteMember({ id: workspaceId, email })) + // .then(() => { + // onClose(); + // onInviteSuccess && onInviteSuccess(); + // }) + // .catch(err => { + // // toast('Invite failed'); + // console.log(err); + // }); }} > Invite diff --git a/packages/app/src/components/login-modal/LoginOptionButton.tsx b/packages/app/src/components/login-modal/LoginOptionButton.tsx index e04d8fecc7..f8e3cdafce 100644 --- a/packages/app/src/components/login-modal/LoginOptionButton.tsx +++ b/packages/app/src/components/login-modal/LoginOptionButton.tsx @@ -9,14 +9,14 @@ export const GoogleLoginButton = () => { return ( { - getDataCenter() - .then(dc => dc.apis.signInWithGoogle?.()) - .then(() => { - triggerLoginModal(); - }) - .catch(error => { - console.log('sign google error', error); - }); + // getDataCenter() + // .then(dc => dc.apis.signInWithGoogle?.()) + // .then(() => { + // triggerLoginModal(); + // }) + // .catch(error => { + // console.log('sign google error', error); + // }); }} > diff --git a/packages/app/src/components/workspace-setting/general/delete/delete.tsx b/packages/app/src/components/workspace-setting/general/delete/delete.tsx index 7fd14ef818..5ba8b120f4 100644 --- a/packages/app/src/components/workspace-setting/general/delete/delete.tsx +++ b/packages/app/src/components/workspace-setting/general/delete/delete.tsx @@ -39,11 +39,11 @@ export const WorkspaceDelete = ({ }; const handleDelete = async () => { - const dc = await getDataCenter(); - await dc.apis.deleteWorkspace({ id: workspaceId }); - router.push(`/workspace/${nextWorkSpaceId}`); - refreshWorkspacesMeta(); - onClose(); + // const dc = await getDataCenter(); + // await dc.apis.deleteWorkspace({ id: workspaceId }); + // router.push(`/workspace/${nextWorkSpaceId}`); + // refreshWorkspacesMeta(); + // onClose(); }; return ( diff --git a/packages/app/src/components/workspace-setting/general/general.tsx b/packages/app/src/components/workspace-setting/general/general.tsx index cef2daccb7..fc3c4cacfd 100644 --- a/packages/app/src/components/workspace-setting/general/general.tsx +++ b/packages/app/src/components/workspace-setting/general/general.tsx @@ -72,19 +72,19 @@ export const GeneralPage = ({ }; const fileChange = async (file: File) => { - setUploading(true); - const blob = new Blob([file], { type: file.type }); - const blobId = await getDataCenter() - .then(dc => dc.apis.uploadBlob({ blob })) - .finally(() => { - setUploading(false); - }); - if (blobId) { - currentWorkspace?.meta.setAvatar(blobId); - workspaces[workspace.id]?.meta.setAvatar(blobId); - setUploading(false); - debouncedRefreshWorkspacesMeta(); - } + // setUploading(true); + // const blob = new Blob([file], { type: file.type }); + // const blobId = await getDataCenter() + // .then(dc => dc.apis.uploadBlob({ blob })) + // .finally(() => { + // setUploading(false); + // }); + // if (blobId) { + // currentWorkspace?.meta.setAvatar(blobId); + // workspaces[workspace.id]?.meta.setAvatar(blobId); + // setUploading(false); + // debouncedRefreshWorkspacesMeta(); + // } }; return workspace ? ( diff --git a/packages/app/src/components/workspace-setting/general/leave/leave.tsx b/packages/app/src/components/workspace-setting/general/leave/leave.tsx index 3c2cf8ce22..baea054915 100644 --- a/packages/app/src/components/workspace-setting/general/leave/leave.tsx +++ b/packages/app/src/components/workspace-setting/general/leave/leave.tsx @@ -28,8 +28,8 @@ export const WorkspaceLeave = ({ const router = useRouter(); const { refreshWorkspacesMeta } = useAppState(); const handleLeave = async () => { - const dc = await getDataCenter(); - await dc.apis.leaveWorkspace({ id: workspaceId }); + // const dc = await getDataCenter(); + // await dc.apis.leaveWorkspace({ id: workspaceId }); router.push(`/workspace/${nextWorkSpaceId}`); refreshWorkspacesMeta(); onClose(); diff --git a/packages/app/src/components/workspace-setting/workspace-setting.tsx b/packages/app/src/components/workspace-setting/workspace-setting.tsx index c1b07e2441..fc11df64bb 100644 --- a/packages/app/src/components/workspace-setting/workspace-setting.tsx +++ b/packages/app/src/components/workspace-setting/workspace-setting.tsx @@ -163,18 +163,18 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => { const [isInviteModalShow, setIsInviteModalShow] = useState(false); const [members, setMembers] = useState([]); const refreshMembers = useCallback(() => { - getDataCenter() - .then(dc => - dc.apis.getWorkspaceMembers({ - id: workspace.id, - }) - ) - .then(data => { - setMembers(data); - }) - .catch(err => { - console.log(err); - }); + // getDataCenter() + // .then(dc => + // dc.apis.getWorkspaceMembers({ + // id: workspace.id, + // }) + // ) + // .then(data => { + // setMembers(data); + // }) + // .catch(err => { + // console.log(err); + // }); }, [workspace.id]); useEffect(() => { refreshMembers(); @@ -233,17 +233,17 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => { // confirmText: 'Delete', // confirmType: 'danger', // }).then(confirm => { - getDataCenter() - .then(dc => - dc.apis.removeMember({ - permissionId: member.id, - }) - ) - .then(() => { - // console.log('data: ', data); - toast('Moved to Trash'); - refreshMembers(); - }); + // getDataCenter() + // .then(dc => + // dc.apis.removeMember({ + // permissionId: member.id, + // }) + // ) + // .then(() => { + // // console.log('data: ', data); + // toast('Moved to Trash'); + // refreshMembers(); + // }); // }); }} icon={} @@ -298,17 +298,17 @@ const PublishPage = ({ workspace }: { workspace: Workspace }) => { workspace.public ); const togglePublic = (flag: boolean) => { - getDataCenter() - .then(dc => - dc.apis.updateWorkspace({ - id: workspace.id, - public: flag, - }) - ) - .then(data => { - setPublicStatus(data?.public); - toast('Updated Public Status Success'); - }); + // getDataCenter() + // .then(dc => + // dc.apis.updateWorkspace({ + // id: workspace.id, + // public: flag, + // }) + // ) + // .then(data => { + // setPublicStatus(data?.public); + // toast('Updated Public Status Success'); + // }); }; const copyUrl = () => { navigator.clipboard.writeText(shareUrl); diff --git a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/SelectorPopperContent.tsx b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/SelectorPopperContent.tsx index 8e101307bb..5a35becfcf 100644 --- a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/SelectorPopperContent.tsx +++ b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/SelectorPopperContent.tsx @@ -54,9 +54,9 @@ export const SelectorPopperContent = ({ if (type === WorkspaceType.Private) { return { id, member_count: 1, owner: user }; } else { - const dc = await getDataCenter(); - const data = await dc.apis.getWorkspaceDetail({ id }); - return { id, ...data } || { id, member_count: 0, owner: user }; + // const dc = await getDataCenter(); + // const data = await dc.apis.getWorkspaceDetail({ id }); + // return { id, ...data } || { id, member_count: 0, owner: user }; } } }) diff --git a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceItem/CreateWorkspaceItem/workspace-create/workspace-create.tsx b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceItem/CreateWorkspaceItem/workspace-create/workspace-create.tsx index b07fdeecac..23434c28d2 100644 --- a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceItem/CreateWorkspaceItem/workspace-create/workspace-create.tsx +++ b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceItem/CreateWorkspaceItem/workspace-create/workspace-create.tsx @@ -52,10 +52,10 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => { ctx.fillText(workspaceName[0], 50, 50); canvas.toBlob(blob => { if (blob) { - const blobId = getDataCenter().then(dc => - dc.apis.uploadBlob({ blob }) - ); - resolve(blobId); + // const blobId = getDataCenter().then(dc => + // dc.apis.uploadBlob({ blob }) + // ); + // resolve(blobId); } else { reject(); } @@ -71,23 +71,23 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => { setCreating(false); }); if (blobId) { - getDataCenter() - .then(dc => - dc.apis.createWorkspace({ name: workspaceName, avatar: blobId }) - ) - .then(async data => { - await refreshWorkspacesMeta(); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - router.push(`/workspace/${data.id}`); - onClose(); - }) - .catch(err => { - console.log(err, 'err'); - }) - .finally(() => { - setCreating(false); - }); + // getDataCenter() + // .then(dc => + // dc.apis.createWorkspace({ name: workspaceName, avatar: blobId }) + // ) + // .then(async data => { + // await refreshWorkspacesMeta(); + // // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // // @ts-ignore + // router.push(`/workspace/${data.id}`); + // onClose(); + // }) + // .catch(err => { + // console.log(err, 'err'); + // }) + // .finally(() => { + // setCreating(false); + // }); } }; return ( diff --git a/packages/app/src/pages/invite/[invite_code].tsx b/packages/app/src/pages/invite/[invite_code].tsx index c6ef0b6b4e..91488a7397 100644 --- a/packages/app/src/pages/invite/[invite_code].tsx +++ b/packages/app/src/pages/invite/[invite_code].tsx @@ -24,19 +24,19 @@ export default function DevPage() { // eslint-disable-next-line @typescript-eslint/no-explicit-any const [inviteData, setInviteData] = useState(null); useEffect(() => { - getDataCenter() - .then(dc => - dc.apis.acceptInviting({ - invitingCode: router.query.invite_code as string, - }) - ) - .then(data => { - setSuccessInvited(true); - setInviteData(data); - }) - .catch(err => { - console.log('err: ', err); - }); + // getDataCenter() + // .then(dc => + // dc.apis.acceptInviting({ + // invitingCode: router.query.invite_code as string, + // }) + // ) + // .then(data => { + // setSuccessInvited(true); + // setInviteData(data); + // }) + // .catch(err => { + // console.log('err: ', err); + // }); }, [router.query.invite_code]); return ( diff --git a/packages/data-center/src/provider/affine/apis/business.ts b/packages/data-center/src/provider/affine/apis/business.ts deleted file mode 100644 index 11a4720851..0000000000 --- a/packages/data-center/src/provider/affine/apis/business.ts +++ /dev/null @@ -1,198 +0,0 @@ -import { uuidv4 } from '@blocksuite/store'; -// import { getDataCenter } from '.'; -// import { DataCenter } from './datacenter'; -// import { Workspace } from '../types'; - -// export class Business { -// private _dc: DataCenter | undefined; - -// private async _getDc() { -// if (!this._dc) { -// this._dc = await getDataCenter(); -// } -// return this._dc; -// } - -// // async createWorkspace( -// // name: string -// // ): Promise> { -// // let id = ''; -// // let type = WorkspaceType.local; -// // this._dc?.load(uuidv4()); -// // const newWorkspaces = (await this.getWorkspaces()).find(w => w.id === id); -// // return { -// // id: newWorkspaces?.id || '', -// // name, -// // avatar: '', -// // type, -// // }; -// // } - -// // not think out a good way to update workspace meta -// // updateWorkspaceMeta( -// // id: string, -// // meta: { name?: string; avatar: Partial } -// // ) {} - -// // async getWorkspaces(focusUpdated?: boolean): Promise { -// // const dc = await this._getDc(); -// // if (focusUpdated) { -// // await dc.workspacesList.refreshWorkspaceList(); -// // } -// // return dc.workspacesList.getWorkspaces(); -// // } - -// /** -// * Get page list by workspace id -// * @param {string} id ID of workspace. -// */ -// getPagesByWorkspaceId(id: string) { -// return []; -// } - -// /** -// * Observe the update of the workspace -// * @param {function} callback({Workspace[]}). -// */ -// async onWorkspaceChange(cb: (workspaces: Workspace[]) => void) { -// const dc = await this._getDc(); -// dc.workspacesList.on('change', cb); -// } - -// async deleteWorkspace(id: string) { -// const dc = await this._getDc(); -// const workspace = dc.workspacesList.getWorkspaces().find(w => w.id === id); -// if (workspace?.type === WorkspaceType.cloud) { -// dc.apis.deleteWorkspace({ id }); -// } -// dc.delete(id); -// } - -// /** -// * The member of the workspace go to leave workspace -// * @param {string} id ID of workspace. -// */ -// async leaveWorkspace(id: string) { -// const dc = await this._getDc(); -// const workspace = dc.workspacesList.getWorkspaces().find(w => w.id === id); -// if (workspace?.type === WorkspaceType.cloud) { -// dc.apis.leaveWorkspace({ id }); -// dc.delete(id); -// } -// } - -// /** -// * Let the workspace to be public -// * @param {string} id ID of workspace. -// * @param {string} isPublish publish flag of workspace. -// */ -// setWorkspacePublish(id: string, isPublish: boolean): boolean { -// return isPublish; -// } - -// /** -// * Get workspace by workspace id -// * @param {string} id ID of workspace. -// */ -// async getWorkspaceById(id: string) { -// const dc = await this._getDc(); -// const workspace = dc.workspacesList.getWorkspaces().find(w => w.id === id); -// if (workspace?.type === WorkspaceType.cloud) { -// return dc.load(id, { providerId: 'affine' }); -// } else { -// return dc.load(id, { providerId: 'local' }); -// } -// } - -// // no time -// /** -// * Get the members of the workspace -// * @param {string} id ID of workspace. -// */ -// getMembers(id: string): any { -// void 0; -// } -// /** -// * Add a new member to the workspace -// * @param {string} id ID of workspace. -// * @param {string} email new member email. -// */ -// inviteMember(id: string, email: string) { -// void 0; -// } - -// /** -// * remove the new member to the workspace -// * @param {string} workspaceId ID of workspace. -// * @param {string} memberId ID of member -// */ -// removeMember(workspaceId: string, memberId: string) { -// void 0; -// } - -// /** -// * A new member click the invite link, finish to join the workspace -// * @param {string} inviteCode token for invitation. -// */ -// async acceptInvitation(invitingCode: string) { -// const dc = await this._getDc(); -// dc.apis.acceptInviting({ invitingCode }); -// } - -// // check with dark sky -// /** -// * Get login user info -// */ -// getUserInfo() { -// void 0; -// } - -// // TODO check with dark sky -// async login() { -// const dc = await this._getDc(); -// await dc.auth('affine'); -// } - -// // just has no time -// /** -// * Logout and clear login session -// */ -// logout() { -// void 0; -// } - -// // need discuss -// /** -// * Create a connection between local and cloud, sync cloud data to local -// * @param {string} id ID of workspace. -// * @param {string} id type of workspace. -// */ -// // setWorkspaceSyncType(id: string, type: 'local' | 'cloud') {} - -// // need discuss -// /** -// * Select a file to import the workspace -// * @param {File} file file of workspace. -// */ -// importWorkspace(file: File) { -// void 0; -// } - -// // need discuss may be not in apis -// // /** -// // * Generate a file ,and export it to local file system -// // * @param {string} id ID of workspace. -// // */ -// exportWorkspace(id: string) { -// void 0; -// } - -// // need discuss -// // /** -// // * Enable workspace cloud flag -// // * @param {string} id ID of workspace. -// // */ -// enableWorkspaceCloud(id: string) { -// void 0; -// } -// }