mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix: blob fetch and state syncing between tabs (#1287)
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
import { atom } from 'jotai';
|
||||
import { createStore } from 'jotai/index';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { createStore } from 'jotai';
|
||||
import { unstable_batchedUpdates } from 'react-dom';
|
||||
|
||||
// workspace necessary atoms
|
||||
export const currentWorkspaceIdAtom = atomWithStorage<string | null>(
|
||||
'affine-current-workspace-id',
|
||||
null
|
||||
);
|
||||
export const currentPageIdAtom = atomWithStorage<string | null>(
|
||||
'affine-current-page-id',
|
||||
null
|
||||
);
|
||||
export const currentWorkspaceIdAtom = atom<string | null>(null);
|
||||
export const currentPageIdAtom = atom<string | null>(null);
|
||||
// If the workspace is locked, it means that the user maybe updating the workspace
|
||||
// from local to remote or vice versa
|
||||
export const workspaceLockAtom = atom(false);
|
||||
|
||||
@@ -16,7 +16,10 @@ export const publicBlockSuiteAtom = atom<Promise<BlockSuiteWorkspace>>(
|
||||
throw new Error('No workspace id');
|
||||
}
|
||||
const binary = await apis.downloadWorkspace(workspaceId, true);
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(workspaceId);
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
workspaceId,
|
||||
(_: string) => undefined
|
||||
);
|
||||
BlockSuiteWorkspace.Y.applyUpdate(
|
||||
blockSuiteWorkspace.doc,
|
||||
new Uint8Array(binary)
|
||||
|
||||
@@ -38,7 +38,10 @@ globalThis.dataCenter = dataCenter;
|
||||
|
||||
function createRemLocalWorkspace(name: string) {
|
||||
const id = nanoid();
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(id);
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
id,
|
||||
(_: string) => undefined
|
||||
);
|
||||
blockSuiteWorkspace.meta.setName(name);
|
||||
const workspace: LocalWorkspace = {
|
||||
flavour: RemWorkspaceFlavour.LOCAL,
|
||||
|
||||
@@ -19,7 +19,11 @@ declare global {
|
||||
|
||||
const BroadcastPage: React.FC = () => {
|
||||
const blockSuiteWorkspace = useMemo(
|
||||
() => createEmptyBlockSuiteWorkspace('broadcast-test'),
|
||||
() =>
|
||||
createEmptyBlockSuiteWorkspace(
|
||||
'broadcast-test',
|
||||
(_: string) => undefined
|
||||
),
|
||||
[]
|
||||
);
|
||||
const [provider, setProvider] = useState<BroadCastChannelProvider | null>(
|
||||
|
||||
@@ -29,7 +29,10 @@ const PreviewPage: NextPage<PreviewPageProps> = ({
|
||||
const [blockSuiteWorkspace, setBlockSuiteWorkspace] =
|
||||
useState<BlockSuiteWorkspace | null>(null);
|
||||
useEffect(() => {
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace('preview');
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
'preview',
|
||||
(_: string) => undefined
|
||||
);
|
||||
blockSuiteWorkspace.signals.pageAdded.once(() => {
|
||||
setBlockSuiteWorkspace(blockSuiteWorkspace);
|
||||
});
|
||||
|
||||
@@ -92,7 +92,10 @@ export const LocalPlugin: WorkspacePlugin<RemWorkspaceFlavour.LOCAL> = {
|
||||
if (config.enableIndexedDBProvider) {
|
||||
const workspaces = await Promise.all(
|
||||
ids.map(id => {
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(id);
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
id,
|
||||
(_: string) => undefined
|
||||
);
|
||||
const workspace: LocalWorkspace = {
|
||||
id,
|
||||
flavour: RemWorkspaceFlavour.LOCAL,
|
||||
@@ -139,7 +142,10 @@ export const LocalPlugin: WorkspacePlugin<RemWorkspaceFlavour.LOCAL> = {
|
||||
}
|
||||
logger.info('no local workspace found, create a new one');
|
||||
const workspaceId = nanoid();
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(workspaceId);
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
workspaceId,
|
||||
(_: string) => undefined
|
||||
);
|
||||
blockSuiteWorkspace.meta.setName('Untitled Workspace');
|
||||
localStorage.setItem(kStoreKey, JSON.stringify([workspaceId]));
|
||||
blockSuiteWorkspace.createPage(nanoid());
|
||||
|
||||
Reference in New Issue
Block a user