refactor!: next generation AFFiNE code structure (#1176)

This commit is contained in:
Himself65
2023-03-01 01:40:01 -06:00
committed by GitHub
parent 2dcccc772c
commit e0481d29ad
270 changed files with 8308 additions and 6829 deletions
@@ -0,0 +1,10 @@
import { useAtom } from 'jotai';
import { currentPageIdAtom } from '../../atoms';
export function useCurrentPageId(): [
string | null,
(newId: string | null) => void
] {
return useAtom(currentPageIdAtom);
}
@@ -0,0 +1,11 @@
import { AccessTokenMessage } from '@affine/datacenter';
import useSWR from 'swr';
import { QueryKey } from '../../plugins/affine/fetcher';
export function useCurrentUser(): AccessTokenMessage | null {
const { data } = useSWR<AccessTokenMessage | null>(QueryKey.getUser, {
fallbackData: null,
});
return data ?? null;
}
@@ -0,0 +1,24 @@
import { useAtom } from 'jotai';
import { useCallback } from 'react';
import { currentPageIdAtom, currentWorkspaceIdAtom } from '../../atoms';
import { RemWorkspace } from '../../shared';
import { useWorkspace } from '../use-workspace';
export function useCurrentWorkspace(): [
RemWorkspace | null,
(id: string | null) => void
] {
const [id, setId] = useAtom(currentWorkspaceIdAtom);
const [, setPageId] = useAtom(currentPageIdAtom);
return [
useWorkspace(id),
useCallback(
(id: string | null) => {
setPageId(null);
setId(id);
},
[setId, setPageId]
),
];
}