feat: change new data center
This commit is contained in:
@@ -60,19 +60,19 @@ export const InviteMembers = ({
|
|||||||
setShowTip(false);
|
setShowTip(false);
|
||||||
debounce(
|
debounce(
|
||||||
() => {
|
() => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.getUserByEmail({
|
// dc.apis.getUserByEmail({
|
||||||
email: value,
|
// email: value,
|
||||||
workspace_id: workspaceId,
|
// workspace_id: workspaceId,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
.then(data => {
|
// .then(data => {
|
||||||
if (data?.name) {
|
// if (data?.name) {
|
||||||
setUserData(data);
|
// setUserData(data);
|
||||||
setShowTip(false);
|
// setShowTip(false);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
300,
|
300,
|
||||||
true
|
true
|
||||||
@@ -134,16 +134,16 @@ export const InviteMembers = ({
|
|||||||
shape="circle"
|
shape="circle"
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc => dc.apis.inviteMember({ id: workspaceId, email }))
|
// .then(dc => dc.apis.inviteMember({ id: workspaceId, email }))
|
||||||
.then(() => {
|
// .then(() => {
|
||||||
onClose();
|
// onClose();
|
||||||
onInviteSuccess && onInviteSuccess();
|
// onInviteSuccess && onInviteSuccess();
|
||||||
})
|
// })
|
||||||
.catch(err => {
|
// .catch(err => {
|
||||||
// toast('Invite failed');
|
// // toast('Invite failed');
|
||||||
console.log(err);
|
// console.log(err);
|
||||||
});
|
// });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Invite
|
Invite
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ export const GoogleLoginButton = () => {
|
|||||||
return (
|
return (
|
||||||
<StyledGoogleButton
|
<StyledGoogleButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc => dc.apis.signInWithGoogle?.())
|
// .then(dc => dc.apis.signInWithGoogle?.())
|
||||||
.then(() => {
|
// .then(() => {
|
||||||
triggerLoginModal();
|
// triggerLoginModal();
|
||||||
})
|
// })
|
||||||
.catch(error => {
|
// .catch(error => {
|
||||||
console.log('sign google error', error);
|
// console.log('sign google error', error);
|
||||||
});
|
// });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ButtonWrapper>
|
<ButtonWrapper>
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ export const WorkspaceDelete = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
const dc = await getDataCenter();
|
// const dc = await getDataCenter();
|
||||||
await dc.apis.deleteWorkspace({ id: workspaceId });
|
// await dc.apis.deleteWorkspace({ id: workspaceId });
|
||||||
router.push(`/workspace/${nextWorkSpaceId}`);
|
// router.push(`/workspace/${nextWorkSpaceId}`);
|
||||||
refreshWorkspacesMeta();
|
// refreshWorkspacesMeta();
|
||||||
onClose();
|
// onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -72,19 +72,19 @@ export const GeneralPage = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fileChange = async (file: File) => {
|
const fileChange = async (file: File) => {
|
||||||
setUploading(true);
|
// setUploading(true);
|
||||||
const blob = new Blob([file], { type: file.type });
|
// const blob = new Blob([file], { type: file.type });
|
||||||
const blobId = await getDataCenter()
|
// const blobId = await getDataCenter()
|
||||||
.then(dc => dc.apis.uploadBlob({ blob }))
|
// .then(dc => dc.apis.uploadBlob({ blob }))
|
||||||
.finally(() => {
|
// .finally(() => {
|
||||||
setUploading(false);
|
// setUploading(false);
|
||||||
});
|
// });
|
||||||
if (blobId) {
|
// if (blobId) {
|
||||||
currentWorkspace?.meta.setAvatar(blobId);
|
// currentWorkspace?.meta.setAvatar(blobId);
|
||||||
workspaces[workspace.id]?.meta.setAvatar(blobId);
|
// workspaces[workspace.id]?.meta.setAvatar(blobId);
|
||||||
setUploading(false);
|
// setUploading(false);
|
||||||
debouncedRefreshWorkspacesMeta();
|
// debouncedRefreshWorkspacesMeta();
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
return workspace ? (
|
return workspace ? (
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export const WorkspaceLeave = ({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { refreshWorkspacesMeta } = useAppState();
|
const { refreshWorkspacesMeta } = useAppState();
|
||||||
const handleLeave = async () => {
|
const handleLeave = async () => {
|
||||||
const dc = await getDataCenter();
|
// const dc = await getDataCenter();
|
||||||
await dc.apis.leaveWorkspace({ id: workspaceId });
|
// await dc.apis.leaveWorkspace({ id: workspaceId });
|
||||||
router.push(`/workspace/${nextWorkSpaceId}`);
|
router.push(`/workspace/${nextWorkSpaceId}`);
|
||||||
refreshWorkspacesMeta();
|
refreshWorkspacesMeta();
|
||||||
onClose();
|
onClose();
|
||||||
|
|||||||
@@ -163,18 +163,18 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
|
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
|
||||||
const [members, setMembers] = useState<Member[]>([]);
|
const [members, setMembers] = useState<Member[]>([]);
|
||||||
const refreshMembers = useCallback(() => {
|
const refreshMembers = useCallback(() => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.getWorkspaceMembers({
|
// dc.apis.getWorkspaceMembers({
|
||||||
id: workspace.id,
|
// id: workspace.id,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
.then(data => {
|
// .then(data => {
|
||||||
setMembers(data);
|
// setMembers(data);
|
||||||
})
|
// })
|
||||||
.catch(err => {
|
// .catch(err => {
|
||||||
console.log(err);
|
// console.log(err);
|
||||||
});
|
// });
|
||||||
}, [workspace.id]);
|
}, [workspace.id]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshMembers();
|
refreshMembers();
|
||||||
@@ -233,17 +233,17 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
// confirmText: 'Delete',
|
// confirmText: 'Delete',
|
||||||
// confirmType: 'danger',
|
// confirmType: 'danger',
|
||||||
// }).then(confirm => {
|
// }).then(confirm => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.removeMember({
|
// dc.apis.removeMember({
|
||||||
permissionId: member.id,
|
// permissionId: member.id,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
.then(() => {
|
// .then(() => {
|
||||||
// console.log('data: ', data);
|
// // console.log('data: ', data);
|
||||||
toast('Moved to Trash');
|
// toast('Moved to Trash');
|
||||||
refreshMembers();
|
// refreshMembers();
|
||||||
});
|
// });
|
||||||
// });
|
// });
|
||||||
}}
|
}}
|
||||||
icon={<TrashIcon />}
|
icon={<TrashIcon />}
|
||||||
@@ -298,17 +298,17 @@ const PublishPage = ({ workspace }: { workspace: Workspace }) => {
|
|||||||
workspace.public
|
workspace.public
|
||||||
);
|
);
|
||||||
const togglePublic = (flag: boolean) => {
|
const togglePublic = (flag: boolean) => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.updateWorkspace({
|
// dc.apis.updateWorkspace({
|
||||||
id: workspace.id,
|
// id: workspace.id,
|
||||||
public: flag,
|
// public: flag,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
.then(data => {
|
// .then(data => {
|
||||||
setPublicStatus(data?.public);
|
// setPublicStatus(data?.public);
|
||||||
toast('Updated Public Status Success');
|
// toast('Updated Public Status Success');
|
||||||
});
|
// });
|
||||||
};
|
};
|
||||||
const copyUrl = () => {
|
const copyUrl = () => {
|
||||||
navigator.clipboard.writeText(shareUrl);
|
navigator.clipboard.writeText(shareUrl);
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ export const SelectorPopperContent = ({
|
|||||||
if (type === WorkspaceType.Private) {
|
if (type === WorkspaceType.Private) {
|
||||||
return { id, member_count: 1, owner: user };
|
return { id, member_count: 1, owner: user };
|
||||||
} else {
|
} else {
|
||||||
const dc = await getDataCenter();
|
// const dc = await getDataCenter();
|
||||||
const data = await dc.apis.getWorkspaceDetail({ id });
|
// const data = await dc.apis.getWorkspaceDetail({ id });
|
||||||
return { id, ...data } || { id, member_count: 0, owner: user };
|
// return { id, ...data } || { id, member_count: 0, owner: user };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
|||||||
ctx.fillText(workspaceName[0], 50, 50);
|
ctx.fillText(workspaceName[0], 50, 50);
|
||||||
canvas.toBlob(blob => {
|
canvas.toBlob(blob => {
|
||||||
if (blob) {
|
if (blob) {
|
||||||
const blobId = getDataCenter().then(dc =>
|
// const blobId = getDataCenter().then(dc =>
|
||||||
dc.apis.uploadBlob({ blob })
|
// dc.apis.uploadBlob({ blob })
|
||||||
);
|
// );
|
||||||
resolve(blobId);
|
// resolve(blobId);
|
||||||
} else {
|
} else {
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
@@ -71,23 +71,23 @@ export const WorkspaceCreate = ({ open, onClose }: WorkspaceCreateProps) => {
|
|||||||
setCreating(false);
|
setCreating(false);
|
||||||
});
|
});
|
||||||
if (blobId) {
|
if (blobId) {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.createWorkspace({ name: workspaceName, avatar: blobId })
|
// dc.apis.createWorkspace({ name: workspaceName, avatar: blobId })
|
||||||
)
|
// )
|
||||||
.then(async data => {
|
// .then(async data => {
|
||||||
await refreshWorkspacesMeta();
|
// await refreshWorkspacesMeta();
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// // @ts-ignore
|
||||||
router.push(`/workspace/${data.id}`);
|
// router.push(`/workspace/${data.id}`);
|
||||||
onClose();
|
// onClose();
|
||||||
})
|
// })
|
||||||
.catch(err => {
|
// .catch(err => {
|
||||||
console.log(err, 'err');
|
// console.log(err, 'err');
|
||||||
})
|
// })
|
||||||
.finally(() => {
|
// .finally(() => {
|
||||||
setCreating(false);
|
// setCreating(false);
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -24,19 +24,19 @@ export default function DevPage() {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const [inviteData, setInviteData] = useState<any>(null);
|
const [inviteData, setInviteData] = useState<any>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getDataCenter()
|
// getDataCenter()
|
||||||
.then(dc =>
|
// .then(dc =>
|
||||||
dc.apis.acceptInviting({
|
// dc.apis.acceptInviting({
|
||||||
invitingCode: router.query.invite_code as string,
|
// invitingCode: router.query.invite_code as string,
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
.then(data => {
|
// .then(data => {
|
||||||
setSuccessInvited(true);
|
// setSuccessInvited(true);
|
||||||
setInviteData(data);
|
// setInviteData(data);
|
||||||
})
|
// })
|
||||||
.catch(err => {
|
// .catch(err => {
|
||||||
console.log('err: ', err);
|
// console.log('err: ', err);
|
||||||
});
|
// });
|
||||||
}, [router.query.invite_code]);
|
}, [router.query.invite_code]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -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;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
Reference in New Issue
Block a user