2024-05-14 08:56:54 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { FC } from "react";
|
2023-08-11 11:48:33 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2024-05-16 07:37:47 +00:00
|
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
2023-08-11 11:48:33 +00:00
|
|
|
// constants
|
2024-05-16 07:37:47 +00:00
|
|
|
import { issueLayoutViews } from "@/constants/issue";
|
2024-05-16 11:47:04 +00:00
|
|
|
// helpers
|
|
|
|
import { queryParamGenerator } from "@/helpers/query-param-generator";
|
2024-05-14 08:56:54 +00:00
|
|
|
// hooks
|
2024-05-16 07:37:47 +00:00
|
|
|
import { useIssueFilter } from "@/hooks/store";
|
2023-08-11 11:48:33 +00:00
|
|
|
// mobx
|
2024-05-16 07:37:47 +00:00
|
|
|
import { TIssueLayout } from "@/types/issue";
|
2024-05-14 08:56:54 +00:00
|
|
|
|
|
|
|
type NavbarIssueBoardViewProps = {
|
2024-05-16 07:37:47 +00:00
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
2024-05-14 08:56:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const NavbarIssueBoardView: FC<NavbarIssueBoardViewProps> = observer((props) => {
|
2024-05-16 07:37:47 +00:00
|
|
|
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();
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
// derived values
|
|
|
|
const activeLayout = issueFilters?.display_filters?.layout || undefined;
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
const handleCurrentBoardView = (boardView: TIssueLayout) => {
|
|
|
|
updateIssueFilters(projectId, "display_filters", "layout", boardView);
|
2024-05-16 11:47:04 +00:00
|
|
|
const { queryParam } = queryParamGenerator({ board: boardView, peekId, priority, state, labels });
|
|
|
|
router.push(`/${workspaceSlug}/${projectId}?${queryParam}`);
|
2023-08-11 11:48:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-05-16 07:37:47 +00:00
|
|
|
{issueLayoutViews &&
|
|
|
|
Object.keys(issueLayoutViews).map((key: string) => {
|
|
|
|
const layoutKey = key as TIssueLayout;
|
|
|
|
if (layoutOptions[layoutKey]) {
|
2023-09-01 11:12:30 +00:00
|
|
|
return (
|
2023-08-11 11:48:33 +00:00
|
|
|
<div
|
2024-05-14 08:56:54 +00:00
|
|
|
key={layoutKey}
|
2023-12-01 07:55:48 +00:00
|
|
|
className={`flex h-[28px] w-[28px] cursor-pointer items-center justify-center rounded-sm ${
|
2024-05-14 08:56:54 +00:00
|
|
|
layoutKey === activeLayout
|
2023-09-01 11:12:30 +00:00
|
|
|
? `bg-custom-background-80 text-custom-text-200`
|
2023-12-01 07:55:48 +00:00
|
|
|
: `text-custom-text-300 hover:bg-custom-background-80`
|
2023-08-11 11:48:33 +00:00
|
|
|
}`}
|
2024-05-14 08:56:54 +00:00
|
|
|
onClick={() => handleCurrentBoardView(layoutKey)}
|
|
|
|
title={layoutKey}
|
2023-08-11 11:48:33 +00:00
|
|
|
>
|
2023-09-01 11:12:30 +00:00
|
|
|
<span
|
|
|
|
className={`material-symbols-rounded text-[18px] ${
|
2024-05-16 07:37:47 +00:00
|
|
|
issueLayoutViews[layoutKey]?.className ? issueLayoutViews[layoutKey]?.className : ``
|
2023-09-01 11:12:30 +00:00
|
|
|
}`}
|
|
|
|
>
|
2024-05-16 07:37:47 +00:00
|
|
|
{issueLayoutViews[layoutKey]?.icon}
|
2023-08-11 11:48:33 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
2023-09-01 11:12:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
})}
|
2023-08-11 11:48:33 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|