"use client"; import { FC, useEffect } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/navigation"; import useSWR from "swr"; // components import { IssuePeekOverview } from "@/components/issues/peek-overview"; // hooks import { useIssueDetails, useLabel, useStates, useCycle, useModule, useMember } from "@/hooks/store"; import { useView } from "@/plane-web/hooks/store/use-published-view"; // store import { PublishStore } from "@/store/publish/publish.store"; // import { BaseCalendarRoot } from "./calendar/base-calendar-root"; import { ViewAppliedFilters } from "./filters/applied-filters/root"; import { BaseGanttRoot } from "./gantt"; import { BaseKanBanRoot } from "./kanban/base-kanban-root"; import { BaseListRoot } from "./list/base-list-root"; import { BaseSpreadsheetRoot } from "./spreadsheet/base-spreadsheet-root"; type Props = { peekId: string | undefined; publishSettings: PublishStore; }; export const ViewLayoutsRoot: FC = observer((props) => { const { peekId, publishSettings } = props; // router const router = useRouter(); // store const issueDetailStore = useIssueDetails(); const { viewData } = useView(); const { fetchStates } = useStates(); const { fetchLabels } = useLabel(); const { fetchCycles } = useCycle(); const { fetchModules } = useModule(); const { fetchMembers } = useMember(); const { anchor } = publishSettings; useSWR(anchor ? `PUBLIC_STATES_${anchor}` : null, anchor ? () => fetchStates(anchor) : null); useSWR(anchor ? `PUBLIC_LABELS_${anchor}` : null, anchor ? () => fetchLabels(anchor) : null); useSWR(anchor ? `PUBLIC_CYCLES_${anchor}` : null, anchor ? () => fetchCycles(anchor) : null); useSWR(anchor ? `PUBLIC_MODULES_${anchor}` : null, anchor ? () => fetchModules(anchor) : null); useSWR(anchor ? `PUBLIC_MEMBERS_${anchor}` : null, anchor ? () => fetchMembers(anchor) : null); // derived values const activeLayout = viewData?.display_filters?.layout ?? "kanban"; useEffect(() => { if (peekId) { issueDetailStore.setPeekId(peekId.toString()); } }, [peekId, issueDetailStore]); const handlePeekClose = () => { issueDetailStore.setPeekId(null); router.push(`/views/${anchor}`); }; if (!anchor) return null; return (
{peekId && } <> {activeLayout && (
{/* applied filters */} {activeLayout === "list" && (
)} {activeLayout === "kanban" && (
)} {activeLayout === "spreadsheet" && (
)} {activeLayout === "calendar" && (
)} {activeLayout === "gantt_chart" && (
)}
)}
); });