chore: move getPageMeta from app-state-provider to page-helper

This commit is contained in:
QiShaoXuan
2022-12-21 12:39:05 +08:00
parent 3be9dbd4a4
commit cb805a07ff
5 changed files with 18 additions and 20 deletions
@@ -71,8 +71,7 @@ export const OperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
export const TrashOperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
const { id } = pageMeta;
const { openPage } = usePageHelper();
const { getPageMeta } = useAppState();
const { openPage, getPageMeta } = usePageHelper();
const { toggleDeletePage, permanentlyDeletePage } = usePageHelper();
const { confirm } = useConfirm();
+13 -2
View File
@@ -1,6 +1,6 @@
import { Workspace } from '@blocksuite/store';
import { QueryContent } from '@blocksuite/store/dist/workspace/search';
import { useAppState } from '@/providers/app-state-provider';
import { PageMeta, useAppState } from '@/providers/app-state-provider';
import { EditorContainer } from '@blocksuite/editor';
import { useChangePageMeta } from '@/hooks/use-change-page-meta';
import { useRouter } from 'next/router';
@@ -11,7 +11,7 @@ export type EditorHandlers = {
pageId: string,
query?: { [key: string]: string }
) => Promise<boolean>;
// getPageMeta: (pageId?: string) => PageMeta;
getPageMeta: (pageId: string) => PageMeta | null;
toggleDeletePage: (pageId: string) => Promise<boolean>;
toggleFavoritePage: (pageId: string) => Promise<boolean>;
permanentlyDeletePage: (pageId: string) => void;
@@ -84,5 +84,16 @@ export const usePageHelper = (): EditorHandlers => {
query,
});
},
getPageMeta: pageId => {
if (!currentWorkspace) {
return null;
}
return (
(currentWorkspace.meta.pageMetas.find(
page => page.id === pageId
) as PageMeta) || null
);
},
};
};
@@ -40,7 +40,6 @@ export interface AppStateContext extends AppStateValue {
createPage?: MutableRefObject<
((pageId?: string) => Promise<string | null>) | undefined
>;
getPageMeta: (pageId: string) => PageMeta | null;
}
export const AppState = createContext<AppStateContext>({
@@ -60,7 +59,6 @@ export const AppState = createContext<AppStateContext>({
loadWorkspace: undefined,
loadPage: undefined,
createPage: undefined,
getPageMeta: () => null,
});
export const useAppState = () => {
@@ -14,7 +14,6 @@ import type {
} from './context';
import type { Page, Workspace } from '@blocksuite/store';
import { EditorContainer } from '@blocksuite/editor';
import { PageMeta } from './interface';
const DynamicBlocksuite = dynamic(() => import('./dynamic-blocksuite'), {
ssr: false,
});
@@ -137,17 +136,6 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
loadWorkspace,
loadPage,
createPage,
getPageMeta: (pageId: string) => {
const { currentWorkspace } = state;
if (!currentWorkspace) {
return null;
}
return (
(currentWorkspace.meta.pageMetas.find(
page => page.id === pageId
) as PageMeta) || null
);
},
}),
[state, setState, loadPage, loadWorkspace]
);
+4 -2
View File
@@ -52,7 +52,10 @@ export type ToastOptions = {
* toast('Hello World');
* ```
*/
export const toast = (message: string, { duration = 2500 }: ToastOptions) => {
export const toast = (
message: string,
{ duration }: ToastOptions = { duration: 2500 }
) => {
if (!ToastContainer) {
ToastContainer = createToastContainer();
}
@@ -105,5 +108,4 @@ export const toast = (message: string, { duration = 2500 }: ToastOptions) => {
return element;
};
export default toast;