mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +08:00
refactor(store): port to useGlobalState with zustand (#1012)
This commit is contained in:
@@ -23,7 +23,7 @@ import Head from 'next/head';
|
||||
import '@affine/i18n';
|
||||
import { useTranslation } from '@affine/i18n';
|
||||
import React from 'react';
|
||||
import { BlockSuiteProvider } from '@/store/workspace';
|
||||
import { GlobalAppProvider } from '@/store/app';
|
||||
|
||||
const ThemeProvider = dynamic(() => import('@/providers/ThemeProvider'), {
|
||||
ssr: false,
|
||||
@@ -68,7 +68,7 @@ const App = ({ Component, pageProps }: AppPropsWithLayout) => {
|
||||
<title>AFFiNE</title>
|
||||
</Head>
|
||||
<Logger />
|
||||
<BlockSuiteProvider key="BlockSuiteProvider">
|
||||
<GlobalAppProvider key="BlockSuiteProvider">
|
||||
<ProviderComposer
|
||||
contexts={[
|
||||
<ThemeProvider key="ThemeProvider" />,
|
||||
@@ -83,7 +83,7 @@ const App = ({ Component, pageProps }: AppPropsWithLayout) => {
|
||||
<AppDefender>{getLayout(<Component {...pageProps} />)}</AppDefender>
|
||||
)}
|
||||
</ProviderComposer>
|
||||
</BlockSuiteProvider>
|
||||
</GlobalAppProvider>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -9,14 +9,14 @@ import { usePageHelper } from '@/hooks/use-page-helper';
|
||||
import dynamic from 'next/dynamic';
|
||||
import Head from 'next/head';
|
||||
import { useTranslation } from '@affine/i18n';
|
||||
import { useBlockSuite } from '@/store/workspace';
|
||||
import { useGlobalState } from '@/store/app';
|
||||
const DynamicBlocksuite = dynamic(() => import('@/components/editor'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
const BlockHubAppender = () => {
|
||||
const setBlockHub = useBlockSuite(store => store.setBlockHub);
|
||||
const editor = useBlockSuite(store => store.editor);
|
||||
const setBlockHub = useGlobalState(store => store.setBlockHub);
|
||||
const editor = useGlobalState(store => store.editor);
|
||||
useEffect(() => {
|
||||
let blockHubElement: HTMLElement | null = null;
|
||||
|
||||
@@ -38,8 +38,8 @@ const BlockHubAppender = () => {
|
||||
};
|
||||
|
||||
const Page: NextPageWithLayout = () => {
|
||||
const currentPage = useBlockSuite(store => store.currentPage);
|
||||
const setEditor = useBlockSuite(store => store.setEditor);
|
||||
const currentPage = useGlobalState(store => store.currentPage);
|
||||
const setEditor = useGlobalState(store => store.setEditor);
|
||||
const { currentWorkspace } = useAppState();
|
||||
|
||||
const { t } = useTranslation();
|
||||
@@ -69,7 +69,7 @@ const Page: NextPageWithLayout = () => {
|
||||
const PageDefender = ({ children }: PropsWithChildren) => {
|
||||
const router = useRouter();
|
||||
const [pageLoaded, setPageLoaded] = useState(false);
|
||||
const loadPage = useBlockSuite(store => store.loadPage);
|
||||
const loadPage = useGlobalState(store => store.loadPage);
|
||||
const { currentWorkspace } = useAppState();
|
||||
const { createPage } = usePageHelper();
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ import { useTranslation } from '@affine/i18n';
|
||||
import { PageListHeader } from '@/components/header';
|
||||
import Head from 'next/head';
|
||||
import { styled } from '@affine/component';
|
||||
import { useGlobalState } from '@/store/app';
|
||||
|
||||
const useTabMap = () => {
|
||||
const { t } = useTranslation();
|
||||
const { isOwner } = useAppState();
|
||||
const isOwner = useGlobalState(store => store.isOwner);
|
||||
const tabMap: {
|
||||
name: string;
|
||||
panelRender: (workspace: WorkspaceUnit) => ReactNode;
|
||||
|
||||
Reference in New Issue
Block a user