mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: adding new contexts and providers
This commit is contained in:
parent
f3748d09a5
commit
08b848c7d8
19
web/contexts/app-root/app-root-provider.tsx
Normal file
19
web/contexts/app-root/app-root-provider.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import { createContext } from "react";
|
||||
// mobx store
|
||||
import { AppRootStore, IAppRootStore } from "store/application";
|
||||
|
||||
let appRootStore: IAppRootStore = new AppRootStore();
|
||||
|
||||
export const AppRootStoreContext = createContext<IAppRootStore>(appRootStore);
|
||||
|
||||
const initializeStore = () => {
|
||||
const _appRootStore: IAppRootStore = appRootStore ?? new AppRootStore();
|
||||
if (typeof window === "undefined") return _appRootStore;
|
||||
if (!appRootStore) appRootStore = _appRootStore;
|
||||
return _appRootStore;
|
||||
};
|
||||
|
||||
export const AppRootStoreProvider = ({ children }: any) => {
|
||||
const store: IAppRootStore = initializeStore();
|
||||
return <AppRootStoreContext.Provider value={store}>{children}</AppRootStoreContext.Provider>;
|
||||
};
|
2
web/contexts/app-root/index.ts
Normal file
2
web/contexts/app-root/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./app-root-provider";
|
||||
export * from "./use-app-root";
|
8
web/contexts/app-root/use-app-root.tsx
Normal file
8
web/contexts/app-root/use-app-root.tsx
Normal file
@ -0,0 +1,8 @@
|
||||
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;
|
||||
};
|
2
web/contexts/page.context/index.ts
Normal file
2
web/contexts/page.context/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./page-provider";
|
||||
export * from "./use-page";
|
20
web/contexts/page.context/page-provider.tsx
Normal file
20
web/contexts/page.context/page-provider.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
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>;
|
||||
};
|
8
web/contexts/page.context/use-page.tsx
Normal file
8
web/contexts/page.context/use-page.tsx
Normal file
@ -0,0 +1,8 @@
|
||||
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;
|
||||
};
|
8
web/hooks/use-page.tsx
Normal file
8
web/hooks/use-page.tsx
Normal file
@ -0,0 +1,8 @@
|
||||
import { useMobxStore } from "lib/mobx/store-provider";
|
||||
|
||||
const usePage = () => {
|
||||
const { page } = useMobxStore();
|
||||
return { ...page };
|
||||
};
|
||||
|
||||
export default usePage;
|
@ -1,5 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext } from "react";
|
||||
// mobx store
|
||||
import { RootStore } from "store_legacy/root";
|
||||
|
@ -82,7 +82,7 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
|
||||
description_html: newDescription,
|
||||
})
|
||||
.then(() => {
|
||||
mutatePageDetails((prevData) => ({ ...prevData, description_html: newDescription }) as IPage, false);
|
||||
mutatePageDetails((prevData) => ({ ...prevData, description_html: newDescription } as IPage), false);
|
||||
});
|
||||
};
|
||||
|
||||
@ -162,15 +162,12 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
|
||||
}, [pageDetails?.description_html]); // TODO: Verify the exhaustive-deps warning
|
||||
|
||||
function createObjectFromArray(keys: string[], options: any): any {
|
||||
return keys.reduce(
|
||||
(obj, key) => {
|
||||
return keys.reduce((obj, key) => {
|
||||
if (options[key] !== undefined) {
|
||||
obj[key] = options[key];
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
{} as { [key: string]: any }
|
||||
);
|
||||
}, {} as { [key: string]: any });
|
||||
}
|
||||
|
||||
const mutatePageDetailsHelper = (
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { observable, action, makeObservable, runInAction } from "mobx";
|
||||
// types
|
||||
import { RootStore } from "../root.store";
|
||||
import { IAppConfig } from "types/app";
|
||||
// services
|
||||
import { AppConfigService } from "services/app_config.service";
|
||||
@ -14,13 +13,10 @@ export interface IAppConfigStore {
|
||||
export class AppConfigStore implements IAppConfigStore {
|
||||
// observables
|
||||
envConfig: IAppConfig | null = null;
|
||||
|
||||
// root store
|
||||
rootStore;
|
||||
// service
|
||||
appConfigService;
|
||||
|
||||
constructor(_rootStore: RootStore) {
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
// observables
|
||||
envConfig: observable.ref,
|
||||
@ -28,9 +24,8 @@ export class AppConfigStore implements IAppConfigStore {
|
||||
fetchAppConfig: action,
|
||||
});
|
||||
this.appConfigService = new AppConfigService();
|
||||
|
||||
this.rootStore = _rootStore;
|
||||
}
|
||||
|
||||
fetchAppConfig = async () => {
|
||||
try {
|
||||
const config = await this.appConfigService.envConfig();
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { observable, action, makeObservable, computed } from "mobx";
|
||||
// types
|
||||
import { RootStore } from "../root.store";
|
||||
// services
|
||||
import { ProjectService } from "services/project";
|
||||
import { PageService } from "services/page.service";
|
||||
@ -58,15 +56,13 @@ export class CommandPaletteStore implements ICommandPaletteStore {
|
||||
isCreateIssueModalOpen: boolean = false;
|
||||
isDeleteIssueModalOpen: boolean = false;
|
||||
isBulkDeleteIssueModalOpen: boolean = false;
|
||||
// root store
|
||||
rootStore;
|
||||
// service
|
||||
projectService;
|
||||
pageService;
|
||||
|
||||
createIssueStoreType: EProjectStore = EProjectStore.PROJECT;
|
||||
|
||||
constructor(_rootStore: RootStore) {
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
// observable
|
||||
isCommandPaletteOpen: observable.ref,
|
||||
@ -95,7 +91,6 @@ export class CommandPaletteStore implements ICommandPaletteStore {
|
||||
toggleBulkDeleteIssueModal: action,
|
||||
});
|
||||
|
||||
this.rootStore = _rootStore;
|
||||
this.projectService = new ProjectService();
|
||||
this.pageService = new PageService();
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { RootStore } from "../root.store";
|
||||
import { AppConfigStore, IAppConfigStore } from "./app-config.store";
|
||||
import { CommandPaletteStore, ICommandPaletteStore } from "./command-palette.store";
|
||||
import { EventTrackerStore, IEventTrackerStore } from "./event-tracker.store";
|
||||
// import { EventTrackerStore, IEventTrackerStore } from "./event-tracker.store";
|
||||
import { InstanceStore, IInstanceStore } from "./instance.store";
|
||||
import { RouterStore, IRouterStore } from "./router.store";
|
||||
import { ThemeStore, IThemeStore } from "./theme.store";
|
||||
@ -9,7 +8,7 @@ import { ThemeStore, IThemeStore } from "./theme.store";
|
||||
export interface IAppRootStore {
|
||||
config: IAppConfigStore;
|
||||
commandPalette: ICommandPaletteStore;
|
||||
eventTracker: IEventTrackerStore;
|
||||
// eventTracker: IEventTrackerStore;
|
||||
instance: IInstanceStore;
|
||||
theme: IThemeStore;
|
||||
router: IRouterStore;
|
||||
@ -18,17 +17,17 @@ export interface IAppRootStore {
|
||||
export class AppRootStore implements IAppRootStore {
|
||||
config: IAppConfigStore;
|
||||
commandPalette: ICommandPaletteStore;
|
||||
eventTracker: IEventTrackerStore;
|
||||
// eventTracker: IEventTrackerStore;
|
||||
instance: IInstanceStore;
|
||||
theme: IThemeStore;
|
||||
router: IRouterStore;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
this.config = new AppConfigStore(rootStore);
|
||||
this.commandPalette = new CommandPaletteStore(rootStore);
|
||||
this.eventTracker = new EventTrackerStore(rootStore);
|
||||
this.instance = new InstanceStore(rootStore);
|
||||
this.theme = new ThemeStore(rootStore);
|
||||
constructor() {
|
||||
this.router = new RouterStore();
|
||||
this.config = new AppConfigStore();
|
||||
this.commandPalette = new CommandPaletteStore();
|
||||
// this.eventTracker = new EventTrackerStore(this.router);
|
||||
this.instance = new InstanceStore();
|
||||
this.theme = new ThemeStore();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { observable, action, computed, makeObservable, runInAction } from "mobx";
|
||||
// store
|
||||
import { RootStore } from "../root.store";
|
||||
// types
|
||||
import { IInstance, IInstanceConfiguration, IFormattedInstanceConfiguration, IInstanceAdmin } from "types/instance";
|
||||
// services
|
||||
@ -31,9 +29,8 @@ export class InstanceStore implements IInstanceStore {
|
||||
configurations: IInstanceConfiguration[] | null = null;
|
||||
// service
|
||||
instanceService;
|
||||
rootStore;
|
||||
|
||||
constructor(_rootStore: RootStore) {
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
// observable
|
||||
loader: observable.ref,
|
||||
@ -51,7 +48,6 @@ export class InstanceStore implements IInstanceStore {
|
||||
updateInstanceConfigurations: action,
|
||||
});
|
||||
|
||||
this.rootStore = _rootStore;
|
||||
this.instanceService = new InstanceService();
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import { PageService } from "services/page.service";
|
||||
// types
|
||||
import { IPage, IRecentPages } from "types";
|
||||
// store
|
||||
import { RootStore } from "./root.store";
|
||||
import { AppRootStore } from "store/application";
|
||||
|
||||
export interface IPageStore {
|
||||
pages: Record<string, IPage>;
|
||||
@ -19,7 +19,7 @@ export interface IPageStore {
|
||||
projectPages: IPage[] | undefined;
|
||||
favoriteProjectPages: IPage[] | undefined;
|
||||
privateProjectPages: IPage[] | undefined;
|
||||
sharedProjectPages: IPage[] | undefined;
|
||||
publicProjectPages: IPage[] | undefined;
|
||||
recentProjectPages: IRecentPages | undefined;
|
||||
// archived pages computed
|
||||
archivedProjectPages: IPage[] | undefined;
|
||||
@ -49,7 +49,7 @@ export class PageStore {
|
||||
// stores
|
||||
router;
|
||||
|
||||
constructor(_rootStore: RootStore) {
|
||||
constructor(appRootStore: AppRootStore) {
|
||||
makeObservable(this, {
|
||||
pages: observable,
|
||||
archivedPages: observable,
|
||||
@ -78,7 +78,7 @@ export class PageStore {
|
||||
restorePage: action,
|
||||
});
|
||||
// stores
|
||||
this.router = _rootStore.app.router;
|
||||
this.router = appRootStore.router;
|
||||
// services
|
||||
this.pageService = new PageService();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user