chore: rename page store

This commit is contained in:
Aaryan Khandelwal 2024-06-13 13:39:45 +05:30
parent 98a0742d5c
commit 950b7a8f46
11 changed files with 28 additions and 29 deletions

View File

@ -9,10 +9,10 @@ import { DeletePageModal } from "@/components/pages";
// helpers // helpers
import { copyUrlToClipboard } from "@/helpers/string.helper"; import { copyUrlToClipboard } from "@/helpers/string.helper";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
type Props = { type Props = {
page: IPageStore; page: IPage;
pageLink: string; pageLink: string;
parentRef: React.RefObject<HTMLElement>; parentRef: React.RefObject<HTMLElement>;
}; };

View File

@ -22,7 +22,7 @@ import { usePageFilters } from "@/hooks/use-page-filters";
// services // services
import { FileService } from "@/services/file.service"; import { FileService } from "@/services/file.service";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
const fileService = new FileService(); const fileService = new FileService();
@ -30,7 +30,7 @@ type Props = {
editorRef: React.RefObject<EditorRefApi>; editorRef: React.RefObject<EditorRefApi>;
readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>; readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>;
markings: IMarking[]; markings: IMarking[];
page: IPageStore; page: IPage;
sidePeekVisible: boolean; sidePeekVisible: boolean;
handleEditorReady: (value: boolean) => void; handleEditorReady: (value: boolean) => void;
handleReadOnlyEditorReady: (value: boolean) => void; handleReadOnlyEditorReady: (value: boolean) => void;

View File

@ -15,12 +15,12 @@ import { renderFormattedDate } from "@/helpers/date-time.helper";
// hooks // hooks
import { useInstance } from "@/hooks/store"; import { useInstance } from "@/hooks/store";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
type Props = { type Props = {
editorRef: React.RefObject<EditorRefApi>; editorRef: React.RefObject<EditorRefApi>;
handleDuplicatePage: () => void; handleDuplicatePage: () => void;
page: IPageStore; page: IPage;
readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>; readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>;
}; };

View File

@ -4,10 +4,10 @@ import { Calendar, History, Info } from "lucide-react";
// helpers // helpers
import { renderFormattedDate } from "@/helpers/date-time.helper"; import { renderFormattedDate } from "@/helpers/date-time.helper";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
type Props = { type Props = {
page: IPageStore; page: IPage;
}; };
export const PageInfoPopover: React.FC<Props> = (props) => { export const PageInfoPopover: React.FC<Props> = (props) => {

View File

@ -5,14 +5,14 @@ import { PageExtraOptions, PageSummaryPopover, PageToolbar } from "@/components/
// hooks // hooks
import { usePageFilters } from "@/hooks/use-page-filters"; import { usePageFilters } from "@/hooks/use-page-filters";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
type Props = { type Props = {
editorRef: React.RefObject<EditorRefApi>; editorRef: React.RefObject<EditorRefApi>;
readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>; readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>;
handleDuplicatePage: () => void; handleDuplicatePage: () => void;
markings: IMarking[]; markings: IMarking[];
page: IPageStore; page: IPage;
sidePeekVisible: boolean; sidePeekVisible: boolean;
setSidePeekVisible: (sidePeekState: boolean) => void; setSidePeekVisible: (sidePeekState: boolean) => void;
editorReady: boolean; editorReady: boolean;

View File

@ -11,14 +11,13 @@ import { copyTextToClipboard, copyUrlToClipboard } from "@/helpers/string.helper
// hooks // hooks
import { useAppRouter } from "@/hooks/store"; import { useAppRouter } from "@/hooks/store";
import { usePageFilters } from "@/hooks/use-page-filters"; import { usePageFilters } from "@/hooks/use-page-filters";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
type Props = { type Props = {
editorRef: EditorRefApi | EditorReadOnlyRefApi | null; editorRef: EditorRefApi | EditorReadOnlyRefApi | null;
handleDuplicatePage: () => void; handleDuplicatePage: () => void;
page: IPageStore; page: IPage;
}; };
export const PageOptionsDropdown: React.FC<Props> = observer((props) => { export const PageOptionsDropdown: React.FC<Props> = observer((props) => {

View File

@ -7,14 +7,14 @@ import { cn } from "@/helpers/common.helper";
// hooks // hooks
import { usePageFilters } from "@/hooks/use-page-filters"; import { usePageFilters } from "@/hooks/use-page-filters";
// store // store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
type Props = { type Props = {
editorRef: React.RefObject<EditorRefApi>; editorRef: React.RefObject<EditorRefApi>;
readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>; readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>;
handleDuplicatePage: () => void; handleDuplicatePage: () => void;
markings: IMarking[]; markings: IMarking[];
page: IPageStore; page: IPage;
sidePeekVisible: boolean; sidePeekVisible: boolean;
setSidePeekVisible: (sidePeekState: boolean) => void; setSidePeekVisible: (sidePeekState: boolean) => void;
editorReady: boolean; editorReady: boolean;

View File

@ -2,13 +2,13 @@ import { useContext } from "react";
// mobx store // mobx store
import { StoreContext } from "@/lib/store-context"; import { StoreContext } from "@/lib/store-context";
// mobx store // mobx store
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
export const usePage = (pageId: string | undefined): IPageStore => { export const usePage = (pageId: string | undefined): IPage => {
const context = useContext(StoreContext); const context = useContext(StoreContext);
if (context === undefined) throw new Error("usePage must be used within StoreProvider"); if (context === undefined) throw new Error("usePage must be used within StoreProvider");
if (!pageId) return {} as IPageStore; if (!pageId) return {} as IPage;
return context.projectPages.data?.[pageId] ?? {}; return context.projectPages.data?.[pageId] ?? {};
}; };

View File

@ -7,12 +7,12 @@ import { EditorRefApi, generateJSONfromHTML } from "@plane/editor-core";
import useReloadConfirmations from "@/hooks/use-reload-confirmation"; import useReloadConfirmations from "@/hooks/use-reload-confirmation";
// services // services
import { ProjectPageService } from "@/services/page"; import { ProjectPageService } from "@/services/page";
import { IPageStore } from "@/store/pages/page.store"; import { IPage } from "@/store/pages/page";
const projectPageService = new ProjectPageService(); const projectPageService = new ProjectPageService();
type Props = { type Props = {
editorRef: React.RefObject<EditorRefApi>; editorRef: React.RefObject<EditorRefApi>;
page: IPageStore; page: IPage;
projectId: string | string[] | undefined; projectId: string | string[] | undefined;
workspaceSlug: string | string[] | undefined; workspaceSlug: string | string[] | undefined;
}; };

View File

@ -12,7 +12,7 @@ import { ProjectPageService } from "@/services/page";
export type TLoader = "submitting" | "submitted" | "saved"; export type TLoader = "submitting" | "submitted" | "saved";
export interface IPageStore extends TPage { export interface IPage extends TPage {
// observables // observables
isSubmitting: TLoader; isSubmitting: TLoader;
// computed // computed
@ -44,7 +44,7 @@ export interface IPageStore extends TPage {
removeFromFavorites: () => Promise<void>; removeFromFavorites: () => Promise<void>;
} }
export class PageStore implements IPageStore { export class Page implements IPage {
// loaders // loaders
isSubmitting: TLoader = "saved"; isSubmitting: TLoader = "saved";
// page properties // page properties

View File

@ -11,7 +11,7 @@ import { RootStore } from "@/plane-web/store/root.store";
// services // services
import { ProjectPageService } from "@/services/page"; import { ProjectPageService } from "@/services/page";
// store // store
import { IPageStore, PageStore } from "@/store/pages/page.store"; import { IPage, Page } from "@/store/pages/page";
type TLoader = "init-loader" | "mutation-loader" | undefined; type TLoader = "init-loader" | "mutation-loader" | undefined;
@ -20,7 +20,7 @@ type TError = { title: string; description: string };
export interface IProjectPageStore { export interface IProjectPageStore {
// observables // observables
loader: TLoader; loader: TLoader;
data: Record<string, IPageStore>; // pageId => PageStore data: Record<string, IPage>; // pageId => Page
error: TError | undefined; error: TError | undefined;
filters: TPageFilters; filters: TPageFilters;
// computed // computed
@ -28,7 +28,7 @@ export interface IProjectPageStore {
// helper actions // helper actions
getCurrentProjectPageIds: (pageType: TPageNavigationTabs) => string[] | undefined; getCurrentProjectPageIds: (pageType: TPageNavigationTabs) => string[] | undefined;
getCurrentProjectFilteredPageIds: (pageType: TPageNavigationTabs) => string[] | undefined; getCurrentProjectFilteredPageIds: (pageType: TPageNavigationTabs) => string[] | undefined;
pageById: (pageId: string) => IPageStore | undefined; pageById: (pageId: string) => IPage | undefined;
updateFilters: <T extends keyof TPageFilters>(filterKey: T, filterValue: TPageFilters[T]) => void; updateFilters: <T extends keyof TPageFilters>(filterKey: T, filterValue: TPageFilters[T]) => void;
clearAllFilters: () => void; clearAllFilters: () => void;
// actions // actions
@ -41,7 +41,7 @@ export interface IProjectPageStore {
export class ProjectPageStore implements IProjectPageStore { export class ProjectPageStore implements IProjectPageStore {
// observables // observables
loader: TLoader = "init-loader"; loader: TLoader = "init-loader";
data: Record<string, IPageStore> = {}; // pageId => PageStore data: Record<string, IPage> = {}; // pageId => Page
error: TError | undefined = undefined; error: TError | undefined = undefined;
filters: TPageFilters = { filters: TPageFilters = {
searchQuery: "", searchQuery: "",
@ -162,7 +162,7 @@ export class ProjectPageStore implements IProjectPageStore {
const pages = await this.service.fetchAll(workspaceSlug, projectId); const pages = await this.service.fetchAll(workspaceSlug, projectId);
runInAction(() => { runInAction(() => {
for (const page of pages) if (page?.id) set(this.data, [page.id], new PageStore(this.store, page)); for (const page of pages) if (page?.id) set(this.data, [page.id], new Page(this.store, page));
this.loader = undefined; this.loader = undefined;
}); });
@ -196,7 +196,7 @@ export class ProjectPageStore implements IProjectPageStore {
const page = await this.service.fetchById(workspaceSlug, projectId, pageId); const page = await this.service.fetchById(workspaceSlug, projectId, pageId);
runInAction(() => { runInAction(() => {
if (page?.id) set(this.data, [page.id], new PageStore(this.store, page)); if (page?.id) set(this.data, [page.id], new Page(this.store, page));
this.loader = undefined; this.loader = undefined;
}); });
@ -229,7 +229,7 @@ export class ProjectPageStore implements IProjectPageStore {
const page = await this.service.create(workspaceSlug, projectId, pageData); const page = await this.service.create(workspaceSlug, projectId, pageData);
runInAction(() => { runInAction(() => {
if (page?.id) set(this.data, [page.id], new PageStore(this.store, page)); if (page?.id) set(this.data, [page.id], new Page(this.store, page));
this.loader = undefined; this.loader = undefined;
}); });