import { useEffect } from "react"; import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/router"; // mobx import { observer } from "mobx-react-lite"; // components import { NavbarSearch } from "./search"; import { NavbarIssueBoardView } from "./issue-board-view"; import { NavbarTheme } from "./theme"; // ui import { PrimaryButton } from "components/ui"; // lib import { useMobxStore } from "lib/mobx/store-provider"; // store import { RootStore } from "store/root"; const renderEmoji = (emoji: string | { name: string; color: string }) => { if (!emoji) return; if (typeof emoji === "object") return ( {emoji.name} ); else return isNaN(parseInt(emoji)) ? emoji : String.fromCodePoint(parseInt(emoji)); }; const IssueNavbar = observer(() => { const { project: projectStore, user: userStore }: RootStore = useMobxStore(); // router const router = useRouter(); const { workspace_slug, project_slug, board } = router.query; const user = userStore?.currentUser; useEffect(() => { if (workspace_slug && project_slug) { projectStore.fetchProjectSettings(workspace_slug.toString(), project_slug.toString()); } }, [projectStore, workspace_slug, project_slug]); useEffect(() => { if (workspace_slug && project_slug && projectStore?.deploySettings) { const viewsAcceptable: string[] = []; let currentBoard: string | null = null; if (projectStore?.deploySettings?.views?.list) viewsAcceptable.push("list"); if (projectStore?.deploySettings?.views?.kanban) viewsAcceptable.push("kanban"); if (projectStore?.deploySettings?.views?.calendar) viewsAcceptable.push("calendar"); if (projectStore?.deploySettings?.views?.gantt) viewsAcceptable.push("gantt"); if (projectStore?.deploySettings?.views?.spreadsheet) viewsAcceptable.push("spreadsheet"); if (board) { if (viewsAcceptable.includes(board.toString())) { currentBoard = board.toString(); } else { if (viewsAcceptable && viewsAcceptable.length > 0) { currentBoard = viewsAcceptable[0]; } } } else { if (viewsAcceptable && viewsAcceptable.length > 0) { currentBoard = viewsAcceptable[0]; } } if (currentBoard) { if (projectStore?.activeBoard === null || projectStore?.activeBoard !== currentBoard) { projectStore.setActiveBoard(currentBoard); router.push({ pathname: `/${workspace_slug}/${project_slug}`, query: { board: currentBoard, }, }); } } } }, [board, workspace_slug, project_slug, router, projectStore, projectStore?.deploySettings]); return (