mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-28 12:52:57 +03:00
feat: switch workspace
This commit is contained in:
parent
bcb8b9f211
commit
9ef0fe9d06
@ -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 (
|
||||
<div>
|
||||
<Modal open={open} onClose={onClose}>
|
||||
@ -50,9 +50,7 @@ export const WorkspaceModal = ({ open, onClose }: LoginModalProps) => {
|
||||
return (
|
||||
<WorkspaceItem
|
||||
onClick={() => {
|
||||
// setActiveWorkspace(item);
|
||||
console.log(item);
|
||||
loadWorkspace(item.id);
|
||||
router.replace(`/workspace/${item.id}`);
|
||||
onClose();
|
||||
}}
|
||||
key={index}
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user