"use client"; import { FC, useEffect } from "react"; import { observer } from "mobx-react-lite"; import Image from "next/image"; import { useSearchParams } from "next/navigation"; import useSWR from "swr"; // components import { IssueKanbanLayoutRoot, IssuesListLayoutRoot } from "@/components/issues"; import { IssueAppliedFilters } from "@/components/issues/filters/applied-filters/root"; import { IssuePeekOverview } from "@/components/issues/peek-overview"; // hooks import { useIssue, useIssueDetails, useIssueFilter } from "@/hooks/store"; // store import { PublishStore } from "@/store/publish/publish.store"; // assets import SomethingWentWrongImage from "public/something-went-wrong.svg"; type Props = { peekId: string | undefined; publishSettings: PublishStore; }; export const IssuesLayoutsRoot: FC = observer((props) => { const { peekId, publishSettings } = props; // query params const searchParams = useSearchParams(); const states = searchParams.get("states") || undefined; const priority = searchParams.get("priority") || undefined; const labels = searchParams.get("labels") || undefined; // store hooks const { getIssueFilters } = useIssueFilter(); const { loader, issues, error, fetchPublicIssues } = useIssue(); const issueDetailStore = useIssueDetails(); // derived values const { anchor } = publishSettings; const issueFilters = anchor ? getIssueFilters(anchor) : undefined; useSWR( anchor ? `PUBLIC_ISSUES_${anchor}` : null, anchor ? () => fetchPublicIssues(anchor, { states, priority, labels }) : null ); useEffect(() => { if (peekId) { issueDetailStore.setPeekId(peekId.toString()); } }, [peekId, issueDetailStore]); // derived values const activeLayout = issueFilters?.display_filters?.layout || undefined; if (!anchor) return null; return (
{peekId && } {loader && !issues ? (
Loading...
) : ( <> {error ? (
Oops! Something went wrong

Oops! Something went wrong.

The public board does not exist. Please check the URL.

) : ( activeLayout && (
{/* applied filters */} {activeLayout === "list" && (
)} {activeLayout === "kanban" && (
)}
) )} )}
); });