"use client"; import { FC } from "react"; import { observer } from "mobx-react-lite"; import { useRouter, useSearchParams } from "next/navigation"; // constants import { issueLayoutViews } from "@/constants/issue"; // hooks import { useIssueFilter } from "@/hooks/store"; // mobx import { TIssueLayout } from "@/types/issue"; type NavbarIssueBoardViewProps = { workspaceSlug: string; projectId: string; }; export const NavbarIssueBoardView: FC = observer((props) => { const router = useRouter(); const searchParams = useSearchParams(); // query params const labels = searchParams.get("labels") || undefined; const state = searchParams.get("state") || undefined; const priority = searchParams.get("priority") || undefined; const peekId = searchParams.get("peekId") || undefined; // props const { workspaceSlug, projectId } = props; // hooks const { layoutOptions, issueFilters, updateIssueFilters } = useIssueFilter(); // derived values const activeLayout = issueFilters?.display_filters?.layout || undefined; const handleCurrentBoardView = (boardView: TIssueLayout) => { updateIssueFilters(projectId, "display_filters", "layout", boardView); let queryParams: any = { board: boardView }; if (peekId && peekId.length > 0) queryParams = { ...queryParams, peekId: peekId }; if (priority && priority.length > 0) queryParams = { ...queryParams, priority: priority }; if (state && state.length > 0) queryParams = { ...queryParams, state: state }; if (labels && labels.length > 0) queryParams = { ...queryParams, labels: labels }; queryParams = new URLSearchParams(queryParams).toString(); router.push(`/${workspaceSlug}/${projectId}?${queryParams}`); }; return ( <> {issueLayoutViews && Object.keys(issueLayoutViews).map((key: string) => { const layoutKey = key as TIssueLayout; if (layoutOptions[layoutKey]) { return (
handleCurrentBoardView(layoutKey)} title={layoutKey} > {issueLayoutViews[layoutKey]?.icon}
); } })} ); });