plane/web/hooks/store/use-page.ts
2024-03-19 20:08:35 +05:30

22 lines
818 B
TypeScript

import { useContext } from "react";
// mobx store
import { StoreContext } from "@/contexts/store-context";
export const usePage = (pageId: string) => {
const context = useContext(StoreContext);
if (context === undefined) throw new Error("usePage must be used within StoreProvider");
const { projectPageMap, projectArchivedPageMap } = context.projectPages;
const { projectId, workspaceSlug } = context.app.router;
if (!projectId || !workspaceSlug) {
console.log("usePage must be used within ProjectProvider");
return;
}
if (projectPageMap[projectId] && projectPageMap[projectId][pageId]) return projectPageMap[projectId][pageId];
else if (projectArchivedPageMap[projectId] && projectArchivedPageMap[projectId][pageId])
return projectArchivedPageMap[projectId][pageId];
else return;
};