mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
Merge branch 'feat/datacenter' of github.com:toeverything/AFFiNE into feat/datacenter
This commit is contained in:
@@ -7,6 +7,9 @@ export const useEnsureWorkspace = () => {
|
||||
const [workspaceLoaded, setWorkspaceLoaded] = useState(false);
|
||||
const { workspaceList, loadWorkspace, user } = useAppState();
|
||||
const router = useRouter();
|
||||
const [activeWorkspaceId, setActiveWorkspaceId] = useState(
|
||||
router.query.workspaceId as string
|
||||
);
|
||||
|
||||
// const defaultOutLineWorkspaceId = '99ce7eb7';
|
||||
// console.log(defaultOutLineWorkspaceId);
|
||||
@@ -35,15 +38,15 @@ export const useEnsureWorkspace = () => {
|
||||
|
||||
const workspaceId =
|
||||
(router.query.workspaceId as string) || workspaceList[0]?.id;
|
||||
|
||||
loadWorkspace(workspaceId).finally(() => {
|
||||
console.log('workspaceId: ', workspaceId);
|
||||
setWorkspaceLoaded(true);
|
||||
setActiveWorkspaceId(activeWorkspaceId);
|
||||
});
|
||||
}, [loadWorkspace, router, user, workspaceList]);
|
||||
|
||||
return {
|
||||
workspaceLoaded,
|
||||
activeWorkspaceId,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -9,23 +9,23 @@ const WorkspaceIndex = () => {
|
||||
const router = useRouter();
|
||||
const { currentWorkspaceId, currentWorkspace } = useAppState();
|
||||
const { createPage } = usePageHelper();
|
||||
const { workspaceLoaded } = useEnsureWorkspace();
|
||||
console.log('workspaceLoaded: ', workspaceLoaded);
|
||||
const { workspaceLoaded, activeWorkspaceId } = useEnsureWorkspace();
|
||||
|
||||
useEffect(() => {
|
||||
const initPage = async () => {
|
||||
if (!workspaceLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const savedPageId = currentWorkspace?.meta.pageMetas[0]?.id;
|
||||
console.log('savedPageId: ', savedPageId);
|
||||
|
||||
if (savedPageId) {
|
||||
router.replace(`/workspace/${currentWorkspaceId}/${savedPageId}`);
|
||||
router.replace(`/workspace/${activeWorkspaceId}/${savedPageId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const pageId = await createPage();
|
||||
router.replace(`/workspace/${currentWorkspaceId}/${pageId}`);
|
||||
router.replace(`/workspace/${activeWorkspaceId}/${pageId}`);
|
||||
};
|
||||
initPage();
|
||||
}, [
|
||||
|
||||
@@ -11,7 +11,6 @@ export const WorkspaceIndex = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (workspaceLoaded) {
|
||||
console.log('workspaceLoaded: ', workspaceLoaded);
|
||||
router.push(`/workspace/${currentWorkspaceId}`);
|
||||
}
|
||||
}, [currentWorkspaceId, router, workspaceLoaded]);
|
||||
|
||||
@@ -89,22 +89,22 @@ export const AppStateProvider = ({
|
||||
|
||||
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
|
||||
loadWorkspace.current = async (workspaceId: string) => {
|
||||
console.log('loadWorkspace');
|
||||
|
||||
const { dataCenter, workspaceList, currentWorkspaceId, currentWorkspace } =
|
||||
appState;
|
||||
if (!workspaceList.find(v => v.id === workspaceId)) {
|
||||
if (!workspaceList.find(v => v.id.toString() === workspaceId)) {
|
||||
return null;
|
||||
}
|
||||
if (workspaceId === currentWorkspaceId) {
|
||||
return currentWorkspace;
|
||||
}
|
||||
|
||||
const workspace = await dataCenter.loadWorkspace(workspaceId);
|
||||
const currentMetaWorkSpace = dataCenter.workspaces.find(
|
||||
(item: WorkspaceInfo) => {
|
||||
return item.id === workspace.room;
|
||||
}
|
||||
);
|
||||
|
||||
setAppState({
|
||||
...appState,
|
||||
currentWorkspace: workspace,
|
||||
|
||||
Reference in New Issue
Block a user