chore: remove currentWorkspaceId & currentMetaWorkspace

This commit is contained in:
QiShaoXuan
2023-01-11 16:33:25 +08:00
parent 8e8e18fdf9
commit 926bb7fd14
19 changed files with 37 additions and 116 deletions

View File

@@ -1,34 +0,0 @@
import { useRouter } from 'next/router';
import { useAppState } from '@/providers/app-state-provider';
import { useEffect, useRef, useState } from 'react';
export const useInitWorkspace = (disabled?: boolean) => {
const [loading, setLoading] = useState(true);
// Do not set as a constant, or it will trigger a hell of re-rendering
const defaultOutLineWorkspaceId = useRef(new Date().getTime().toString());
const router = useRouter();
const { workspaceList, loadWorkspace, currentWorkspace, currentWorkspaceId } =
useAppState();
const workspaceId =
(router.query.workspaceId as string) ||
workspaceList?.[0]?.id ||
defaultOutLineWorkspaceId.current;
useEffect(() => {
if (disabled) {
setLoading(false);
return;
}
setLoading(true);
loadWorkspace(workspaceId).finally(() => {
setLoading(false);
});
}, [workspaceId, disabled, loadWorkspace]);
return {
workspaceId,
workspace: workspaceId === currentWorkspaceId ? currentWorkspace : null,
loading,
};
};

View File

@@ -36,7 +36,7 @@ const getPageMeta = (workspace: WorkspaceUnit | null, pageId: string) => {
export const usePageHelper = (): EditorHandlers => {
const router = useRouter();
const changePageMeta = useChangePageMeta();
const { currentWorkspace, editor, currentWorkspaceId } = useAppState();
const { currentWorkspace, editor } = useAppState();
return {
createPage: ({
@@ -109,11 +109,11 @@ export const usePageHelper = (): EditorHandlers => {
pageId = pageId.replace('space:', '');
if (newTab) {
window.open(`/workspace/${currentWorkspaceId}/${pageId}`, '_blank');
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
return Promise.resolve(true);
}
return router.push({
pathname: `/workspace/${currentWorkspaceId}/${pageId}`,
pathname: `/workspace/${currentWorkspace?.id}/${pageId}`,
query,
});
},

View File

@@ -6,8 +6,7 @@ import router from 'next/router';
export const useWorkspaceHelper = () => {
const { confirm } = useConfirm();
const { dataCenter, currentWorkspace, user, login, currentMetaWorkSpace } =
useAppState();
const { dataCenter, currentWorkspace, user, login } = useAppState();
const createWorkspace = async (name: string) => {
const workspaceInfo = await dataCenter.createWorkspace({
name: name,
@@ -58,8 +57,8 @@ export const useWorkspaceHelper = () => {
};
const inviteMember = async (email: string) => {
currentMetaWorkSpace &&
(await dataCenter.inviteMember(currentMetaWorkSpace?.id, email));
currentWorkspace &&
(await dataCenter.inviteMember(currentWorkspace?.id, email));
};
return {