feat: change new data center

This commit is contained in:
MingLiang Wang 2023-01-09 10:53:18 +08:00
parent bf3621eaef
commit dd529f8035
10 changed files with 122 additions and 320 deletions

View File

@ -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

View File

@ -9,14 +9,14 @@ export const GoogleLoginButton = () => {
return (
<StyledGoogleButton
onClick={() => {
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);
// });
}}
>
<ButtonWrapper>

View File

@ -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 (

View File

@ -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 ? (

View File

@ -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();

View File

@ -163,18 +163,18 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
const [members, setMembers] = useState<Member[]>([]);
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={<TrashIcon />}
@ -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);

View File

@ -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 };
}
}
})

View File

@ -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 (

View File

@ -24,19 +24,19 @@ export default function DevPage() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [inviteData, setInviteData] = useState<any>(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 (

View File

@ -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<Pick<Workspace, 'id' | 'name' | 'avatar' | 'type'>> {
// // 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<WorkspaceMeta> }
// // ) {}
// // async getWorkspaces(focusUpdated?: boolean): Promise<Workspace[]> {
// // 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;
// }
// }