mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
feat!: affine cloud support (#3813)
Co-authored-by: Hongtao Lye <codert.sn@gmail.com> Co-authored-by: liuyi <forehalo@gmail.com> Co-authored-by: LongYinan <lynweklm@gmail.com> Co-authored-by: X1a0t <405028157@qq.com> Co-authored-by: JimmFly <yangjinfei001@gmail.com> Co-authored-by: Peng Xiao <pengxiao@outlook.com> Co-authored-by: xiaodong zuo <53252747+zuoxiaodong0815@users.noreply.github.com> Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: Qi <474021214@qq.com> Co-authored-by: danielchim <kahungchim@gmail.com>
This commit is contained in:
@@ -14,7 +14,6 @@ import { beforeEach } from 'vitest';
|
||||
|
||||
import { useBlockSuitePagePreview } from '../use-block-suite-page-preview';
|
||||
import { useBlockSuiteWorkspaceName } from '../use-block-suite-workspace-name';
|
||||
import { useBlockSuiteWorkspacePageIsPublic } from '../use-block-suite-workspace-page-is-public';
|
||||
import { useBlockSuiteWorkspacePageTitle } from '../use-block-suite-workspace-page-title';
|
||||
|
||||
let blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||
@@ -66,19 +65,6 @@ describe('useBlockSuiteWorkspacePageTitle', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('useBlockSuiteWorkspacePageIsPublic', () => {
|
||||
test('basic', async () => {
|
||||
const page = blockSuiteWorkspace.getPage('page0') as Page;
|
||||
expect(page).not.toBeNull();
|
||||
const hook = renderHook(() => useBlockSuiteWorkspacePageIsPublic(page));
|
||||
expect(hook.result.current[0]).toBe(false);
|
||||
hook.result.current[1](true);
|
||||
expect(page.meta.isPublic).toBe(true);
|
||||
hook.rerender();
|
||||
expect(hook.result.current[0]).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useBlockSuitePagePreview', () => {
|
||||
test('basic', async () => {
|
||||
const page = blockSuiteWorkspace.getPage('page0') as Page;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import type { Atom, WritableAtom } from 'jotai';
|
||||
import { atom, useAtom } from 'jotai';
|
||||
|
||||
const weakMap = new WeakMap<
|
||||
Page,
|
||||
WritableAtom<boolean, [boolean], void> & Atom<boolean>
|
||||
>();
|
||||
|
||||
export function useBlockSuiteWorkspacePageIsPublic(page: Page) {
|
||||
if (!weakMap.has(page)) {
|
||||
const baseAtom = atom<boolean>(page.meta.isPublic ?? false);
|
||||
const writableAtom = atom(
|
||||
get => get(baseAtom),
|
||||
(_, set, isPublic: boolean) => {
|
||||
page.workspace.setPageMeta(page.id, {
|
||||
isPublic,
|
||||
});
|
||||
set(baseAtom, isPublic);
|
||||
}
|
||||
);
|
||||
baseAtom.onMount = set => {
|
||||
const disposable = page.workspace.meta.pageMetasUpdated.on(() => {
|
||||
set(page.meta.isPublic ?? false);
|
||||
});
|
||||
return () => {
|
||||
disposable.dispose();
|
||||
};
|
||||
};
|
||||
weakMap.set(page, writableAtom);
|
||||
}
|
||||
const isPublicAtom = weakMap.get(page);
|
||||
assertExists(isPublicAtom);
|
||||
return useAtom(isPublicAtom);
|
||||
}
|
||||
Reference in New Issue
Block a user