mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
Merge branch 'refactor/mobx-store' of github.com:makeplane/plane into refactor/mobx-store
This commit is contained in:
commit
39ac5a87ca
web
contexts
pages/[workspaceSlug]/projects/[projectId]/pages
@ -1,4 +1,4 @@
|
|||||||
import { createContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
// mobx store
|
// mobx store
|
||||||
import { AppRootStore, IAppRootStore } from "store/application";
|
import { AppRootStore, IAppRootStore } from "store/application";
|
||||||
|
|
||||||
@ -17,3 +17,9 @@ export const AppRootStoreProvider = ({ children }: any) => {
|
|||||||
const store: IAppRootStore = initializeStore();
|
const store: IAppRootStore = initializeStore();
|
||||||
return <AppRootStoreContext.Provider value={store}>{children}</AppRootStoreContext.Provider>;
|
return <AppRootStoreContext.Provider value={store}>{children}</AppRootStoreContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useAppRootStore = () => {
|
||||||
|
const context = useContext(AppRootStoreContext);
|
||||||
|
if (context === undefined) throw new Error("useMobxStore must be used within MobxStoreProvider");
|
||||||
|
return context;
|
||||||
|
};
|
@ -1,2 +0,0 @@
|
|||||||
export * from "./app-root-provider";
|
|
||||||
export * from "./use-app-root";
|
|
@ -1,8 +0,0 @@
|
|||||||
import { useContext } from "react";
|
|
||||||
import { AppRootStoreContext } from "./app-root-provider";
|
|
||||||
|
|
||||||
export const useAppRoot = () => {
|
|
||||||
const context = useContext(AppRootStoreContext);
|
|
||||||
if (context === undefined) throw new Error("useAppRoot must be used within AppRootStoreContext");
|
|
||||||
return context;
|
|
||||||
};
|
|
21
web/contexts/page.context.tsx
Normal file
21
web/contexts/page.context.tsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { createContext, useContext } from "react";
|
||||||
|
// mobx store
|
||||||
|
import { PageStore } from "store/page.store";
|
||||||
|
import { AppRootStore } from "store/application";
|
||||||
|
import { useAppRootStore } from "./app-root.context";
|
||||||
|
|
||||||
|
export const PageContext = createContext<PageStore | undefined>(undefined);
|
||||||
|
|
||||||
|
let pageStore: PageStore | undefined;
|
||||||
|
|
||||||
|
export const PageStoreProvider = ({ children }: any) => {
|
||||||
|
const appRootStore = useAppRootStore();
|
||||||
|
pageStore = pageStore ?? new PageStore(appRootStore);
|
||||||
|
return <PageContext.Provider value={pageStore}>{children}</PageContext.Provider>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const usePage = () => {
|
||||||
|
const context = useContext(PageContext);
|
||||||
|
if (context === undefined) throw new Error("usePage must be used within AppRootStoreContext");
|
||||||
|
return context;
|
||||||
|
};
|
@ -1,2 +0,0 @@
|
|||||||
export * from "./page-provider";
|
|
||||||
export * from "./use-page";
|
|
@ -1,20 +0,0 @@
|
|||||||
import { createContext } from "react";
|
|
||||||
// mobx store
|
|
||||||
import { PageStore } from "store/page.store";
|
|
||||||
import { AppRootStore } from "store/application";
|
|
||||||
|
|
||||||
let pageStore: PageStore = new PageStore(new AppRootStore());
|
|
||||||
|
|
||||||
export const PageContext = createContext<PageStore>(pageStore);
|
|
||||||
|
|
||||||
const initializeStore = () => {
|
|
||||||
const _pageStore: PageStore = pageStore ?? new PageStore(pageStore);
|
|
||||||
if (typeof window === "undefined") return _pageStore;
|
|
||||||
if (!pageStore) pageStore = _pageStore;
|
|
||||||
return _pageStore;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AppRootStoreProvider = ({ children }: any) => {
|
|
||||||
const store: PageStore = initializeStore();
|
|
||||||
return <PageContext.Provider value={store}>{children}</PageContext.Provider>;
|
|
||||||
};
|
|
@ -1,8 +0,0 @@
|
|||||||
import { useContext } from "react";
|
|
||||||
import { PageContext } from "./page-provider";
|
|
||||||
|
|
||||||
export const usePage = () => {
|
|
||||||
const context = useContext(PageContext);
|
|
||||||
if (context === undefined) throw new Error("useAppRoot must be used within AppRootStoreContext");
|
|
||||||
return context;
|
|
||||||
};
|
|
@ -17,6 +17,7 @@ import { PagesHeader } from "components/headers";
|
|||||||
import { NextPageWithLayout } from "types/app";
|
import { NextPageWithLayout } from "types/app";
|
||||||
// constants
|
// constants
|
||||||
import { PAGE_TABS_LIST } from "constants/page";
|
import { PAGE_TABS_LIST } from "constants/page";
|
||||||
|
import { PageStoreProvider } from "contexts/page.context";
|
||||||
|
|
||||||
const AllPagesList = dynamic<any>(() => import("components/pages").then((a) => a.AllPagesList), {
|
const AllPagesList = dynamic<any>(() => import("components/pages").then((a) => a.AllPagesList), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@ -82,6 +83,7 @@ const ProjectPagesPage: NextPageWithLayout = observer(() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<PageStoreProvider>
|
||||||
<>
|
<>
|
||||||
{workspaceSlug && projectId && (
|
{workspaceSlug && projectId && (
|
||||||
<CreateUpdatePageModal
|
<CreateUpdatePageModal
|
||||||
@ -157,6 +159,7 @@ const ProjectPagesPage: NextPageWithLayout = observer(() => {
|
|||||||
</Tab.Group>
|
</Tab.Group>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
</PageStoreProvider>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user