plane/web/hooks/store/use-view-detail.tsx

35 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-02-02 08:22:38 +00:00
import { useContext } from "react";
// mobx store
import { StoreContext } from "contexts/store-context";
// store
import { TViewStore } from "store/view/view.store";
// types
import { TViewTypes } from "@plane/types";
export const useViewDetail = (
workspaceSlug: string,
projectId: string | undefined,
viewId: string,
viewType: TViewTypes | undefined
): TViewStore | undefined => {
const context = useContext(StoreContext);
if (context === undefined) throw new Error("useViewDetail must be used within StoreProvider");
2024-02-05 14:39:17 +00:00
if (!workspaceSlug || !viewId) return undefined;
2024-02-02 08:22:38 +00:00
switch (viewType) {
case "WORKSPACE_YOUR_VIEWS":
return context.view.workspaceViewMeStore.viewById(viewId);
2024-02-05 14:39:17 +00:00
case "WORKSPACE_VIEWS":
return context.view.workspaceViewStore.viewById(viewId);
2024-02-02 08:22:38 +00:00
case "PROJECT_YOUR_VIEWS":
if (!projectId) throw new Error("useView hook must require projectId");
return context.view.projectViewMeStore.viewById(viewId);
case "PROJECT_VIEWS":
if (!projectId) throw new Error("useView hook must require projectId");
return context.view.projectViewStore.viewById(viewId);
default:
2024-02-05 14:39:17 +00:00
return undefined;
2024-02-02 08:22:38 +00:00
}
};