diff --git a/packages/app/src/components/workspace-modal/index.tsx b/packages/app/src/components/workspace-modal/index.tsx
index f223c7b87d..c5c9c4b8f7 100644
--- a/packages/app/src/components/workspace-modal/index.tsx
+++ b/packages/app/src/components/workspace-modal/index.tsx
@@ -13,19 +13,19 @@ import {
import { useConfirm } from '@/providers/ConfirmProvider';
import { toast } from '@/ui/toast';
import { WorkspaceAvatar } from '@/components/workspace-avatar';
-// import { useTemporaryHelper } from '@/providers/temporary-helper-provider';
import { useAppState } from '@/providers/app-state-provider';
+import { useRouter } from 'next/router';
-interface LoginModalProps {
+interface WorkspaceModalProps {
open: boolean;
onClose: () => void;
}
-export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
+export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
const { confirm } = useConfirm();
- const { user, workspaceList, loadWorkspace } = useAppState();
-
+ const { user, workspaceList } = useAppState();
+ const router = useRouter();
return (
@@ -50,9 +50,7 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
return (
{
- // setActiveWorkspace(item);
- console.log(item);
- loadWorkspace(item.id);
+ router.replace(`/workspace/${item.id}`);
onClose();
}}
key={index}
diff --git a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx
index 98a875f55e..f829f3c89d 100644
--- a/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx
+++ b/packages/app/src/components/workspace-slider-bar/WorkspaceSelector/WorkspaceSelector.tsx
@@ -2,7 +2,6 @@ import { Avatar, WorkspaceName, SelectorWrapper } from './styles';
import { useEffect, useState } from 'react';
import { WorkspaceModal } from '@/components/workspace-modal';
import { WorkspaceAvatar } from '@/components/workspace-avatar';
-import { useTemporaryHelper } from '@/providers/temporary-helper-provider';
import { useAppState } from '@/providers/app-state-provider';
export const WorkspaceSelector = () => {
const [workspaceListShow, setWorkspaceListShow] = useState(false);
diff --git a/packages/app/src/providers/app-state-provider/Provider.tsx b/packages/app/src/providers/app-state-provider/Provider.tsx
index 9c65aae97c..9e3b451bcd 100644
--- a/packages/app/src/providers/app-state-provider/Provider.tsx
+++ b/packages/app/src/providers/app-state-provider/Provider.tsx
@@ -43,10 +43,12 @@ export const AppStateProvider = ({
if (dataCenter.workspaces.length === 0) {
await createDefaultWorkspace(dataCenter);
}
-
- const currentWorkspace = await dataCenter.loadWorkspace(
- dataCenter.workspaces[0].id
- );
+ let currentWorkspace = appState.currentWorkspace;
+ if (!currentWorkspace) {
+ currentWorkspace = await dataCenter.loadWorkspace(
+ dataCenter.workspaces[0].id
+ );
+ }
setAppState({
dataCenter,
@@ -104,6 +106,7 @@ export const AppStateProvider = ({
};
const loadWorkspace = async (workspaceId: string) => {
+ console.log('workspaceId: ', workspaceId);
const { dataCenter, workspaceList, currentWorkspaceId } = appState;
if (!workspaceList.find(v => v.id === workspaceId)) {
return;
@@ -111,6 +114,8 @@ export const AppStateProvider = ({
if (workspaceId === currentWorkspaceId) {
return;
}
+ const workspace = await dataCenter.loadWorkspace(workspaceId);
+ console.log('workspace: ', workspace);
setAppState({
...appState,
diff --git a/packages/data-center/src/provider/local/local.ts b/packages/data-center/src/provider/local/local.ts
index 82ffe77741..2c118ca586 100644
--- a/packages/data-center/src/provider/local/local.ts
+++ b/packages/data-center/src/provider/local/local.ts
@@ -25,8 +25,9 @@ export class LocalProvider extends BaseProvider {
public override async linkLocal(workspace: Workspace) {
assert(workspace.room);
let idb = this._idbMap.get(workspace.room);
- idb?.destroy();
- idb = new IndexedDBProvider(workspace.room, workspace.doc);
+ if (!idb) {
+ idb = new IndexedDBProvider(workspace.room, workspace.doc);
+ }
this._idbMap.set(workspace.room, idb);
this._logger('Local data loaded');
return workspace;