"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 { IssueCalendarView } from "@/components/issues/board-views/calendar"; import { IssueGanttView } from "@/components/issues/board-views/gantt"; import { IssueKanbanView } from "@/components/issues/board-views/kanban"; import { IssueListView } from "@/components/issues/board-views/list"; import { IssueSpreadsheetView } from "@/components/issues/board-views/spreadsheet"; import { IssueAppliedFilters } from "@/components/issues/filters/applied-filters/root"; import { IssuePeekOverview } from "@/components/issues/peek-overview"; // mobx store import { useIssue, useUser, useIssueDetails, useIssueFilter, useProject } from "@/hooks/store"; // assets import SomethingWentWrongImage from "public/something-went-wrong.svg"; type ProjectDetailsViewProps = { workspaceSlug: string; projectId: string; peekId: string | undefined; }; export const ProjectDetailsView: FC = observer((props) => { // router const searchParams = useSearchParams(); // query params const states = searchParams.get("states") || undefined; const priority = searchParams.get("priority") || undefined; const labels = searchParams.get("labels") || undefined; const { workspaceSlug, projectId, peekId } = props; // hooks const { fetchProjectSettings } = useProject(); const { issueFilters } = useIssueFilter(); const { loader, issues, error, fetchPublicIssues } = useIssue(); const issueDetailStore = useIssueDetails(); const { data: currentUser, fetchCurrentUser } = useUser(); useSWR( workspaceSlug && projectId ? "WORKSPACE_PROJECT_SETTINGS" : null, workspaceSlug && projectId ? () => fetchProjectSettings(workspaceSlug, projectId) : null ); useSWR( (workspaceSlug && projectId) || states || priority || labels ? "WORKSPACE_PROJECT_PUBLIC_ISSUES" : null, (workspaceSlug && projectId) || states || priority || labels ? () => fetchPublicIssues(workspaceSlug, projectId, { states, priority, labels }) : null ); useSWR( workspaceSlug && projectId && !currentUser ? "WORKSPACE_PROJECT_CURRENT_USER" : null, workspaceSlug && projectId && !currentUser ? () => fetchCurrentUser() : null ); useEffect(() => { if (peekId && workspaceSlug && projectId) { issueDetailStore.setPeekId(peekId.toString()); } }, [peekId, issueDetailStore, projectId, workspaceSlug]); // derived values const activeLayout = issueFilters?.display_filters?.layout || undefined; return (
{workspaceSlug && projectId && 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" && (
)} {activeLayout === "calendar" && } {activeLayout === "spreadsheet" && } {activeLayout === "gantt" && }
) )} )}
); });