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";
|
2024-02-08 18:11:30 +00:00
|
|
|
// constants
|
|
|
|
import { VIEW_TYPES } from "constants/view";
|
2024-02-02 08:22:38 +00:00
|
|
|
|
|
|
|
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) {
|
2024-02-08 18:11:30 +00:00
|
|
|
case VIEW_TYPES.WORKSPACE_PRIVATE_VIEWS:
|
|
|
|
return context.view.workspacePrivateViewStore.viewById(viewId);
|
|
|
|
case VIEW_TYPES.WORKSPACE_PUBLIC_VIEWS:
|
|
|
|
return context.view.workspacePublicViewStore.viewById(viewId);
|
|
|
|
case VIEW_TYPES.PROJECT_PRIVATE_VIEWS:
|
|
|
|
if (!projectId) return undefined;
|
|
|
|
return context.view.projectPrivateViewStore.viewById(viewId);
|
|
|
|
case VIEW_TYPES.PROJECT_PUBLIC_VIEWS:
|
|
|
|
if (!projectId) return undefined;
|
|
|
|
return context.view.projectPublicViewStore.viewById(viewId);
|
2024-02-02 08:22:38 +00:00
|
|
|
default:
|
2024-02-05 14:39:17 +00:00
|
|
|
return undefined;
|
2024-02-02 08:22:38 +00:00
|
|
|
}
|
|
|
|
};
|