mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
chore: remove currentWorkspaceId & currentMetaWorkspace
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user