2023-09-01 11:12:30 +00:00
|
|
|
import { useEffect } from "react";
|
2023-09-01 11:40:06 +00:00
|
|
|
|
|
|
|
import Link from "next/link";
|
2023-08-16 07:45:57 +00:00
|
|
|
import Image from "next/image";
|
2023-09-01 11:12:30 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-09-01 11:40:06 +00:00
|
|
|
|
|
|
|
// mobx
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-08-11 11:48:33 +00:00
|
|
|
// components
|
|
|
|
import { NavbarSearch } from "./search";
|
|
|
|
import { NavbarIssueBoardView } from "./issue-board-view";
|
|
|
|
import { NavbarTheme } from "./theme";
|
2023-09-01 11:40:06 +00:00
|
|
|
// ui
|
|
|
|
import { PrimaryButton } from "components/ui";
|
2023-09-01 11:12:30 +00:00
|
|
|
// lib
|
2023-08-11 11:48:33 +00:00
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-09-01 11:12:30 +00:00
|
|
|
// store
|
2023-08-11 11:48:33 +00:00
|
|
|
import { RootStore } from "store/root";
|
|
|
|
|
2023-08-16 07:45:57 +00:00
|
|
|
const renderEmoji = (emoji: string | { name: string; color: string }) => {
|
|
|
|
if (!emoji) return;
|
|
|
|
|
|
|
|
if (typeof emoji === "object")
|
|
|
|
return (
|
|
|
|
<span style={{ color: emoji.color }} className="material-symbols-rounded text-lg">
|
|
|
|
{emoji.name}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
else return isNaN(parseInt(emoji)) ? emoji : String.fromCodePoint(parseInt(emoji));
|
|
|
|
};
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
const IssueNavbar = observer(() => {
|
2023-09-01 11:40:06 +00:00
|
|
|
const { project: projectStore, user: userStore }: RootStore = useMobxStore();
|
2023-09-01 11:12:30 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspace_slug, project_slug, board } = router.query;
|
|
|
|
|
2023-09-01 11:40:06 +00:00
|
|
|
const user = userStore?.currentUser;
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (workspace_slug && project_slug) {
|
|
|
|
projectStore.fetchProjectSettings(workspace_slug.toString(), project_slug.toString());
|
|
|
|
}
|
|
|
|
}, [projectStore, workspace_slug, project_slug]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-09-03 20:20:49 +00:00
|
|
|
if (workspace_slug && project_slug) {
|
|
|
|
if (!board) {
|
|
|
|
router.push({
|
|
|
|
pathname: `/${workspace_slug}/${project_slug}`,
|
|
|
|
query: {
|
|
|
|
board: "list",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return projectStore.setActiveBoard("list");
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
2023-09-03 20:20:49 +00:00
|
|
|
projectStore.setActiveBoard(board.toString());
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
2023-09-03 20:20:49 +00:00
|
|
|
}, [board, workspace_slug, project_slug]);
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="px-5 relative w-full flex items-center gap-4">
|
|
|
|
{/* project detail */}
|
|
|
|
<div className="flex-shrink-0 flex items-center gap-2">
|
2023-09-01 11:12:30 +00:00
|
|
|
<div className="w-4 h-4 flex justify-center items-center">
|
|
|
|
{projectStore?.project && projectStore?.project?.emoji ? (
|
|
|
|
renderEmoji(projectStore?.project?.emoji)
|
2023-08-16 07:45:57 +00:00
|
|
|
) : (
|
|
|
|
<Image src="/plane-logo.webp" alt="plane logo" className="w-[24px] h-[24px]" height="24" width="24" />
|
|
|
|
)}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
<div className="font-medium text-lg max-w-[300px] line-clamp-1 overflow-hidden">
|
2023-09-01 11:12:30 +00:00
|
|
|
{projectStore?.project?.name || `...`}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* issue search bar */}
|
|
|
|
<div className="w-full">
|
|
|
|
<NavbarSearch />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* issue views */}
|
|
|
|
<div className="flex-shrink-0 relative flex items-center gap-1 transition-all ease-in-out delay-150">
|
|
|
|
<NavbarIssueBoardView />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* theming */}
|
2023-09-01 11:12:30 +00:00
|
|
|
<div className="flex-shrink-0 relative">
|
2023-08-11 11:48:33 +00:00
|
|
|
<NavbarTheme />
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
2023-09-01 11:40:06 +00:00
|
|
|
|
|
|
|
{user ? (
|
|
|
|
<div className="border border-custom-border-200 rounded flex items-center gap-2 p-2">
|
|
|
|
{user.avatar && user.avatar !== "" ? (
|
|
|
|
<div className="h-5 w-5 rounded-full">
|
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
|
|
<img src={user.avatar} alt={user.display_name ?? ""} className="rounded-full" />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="bg-custom-background-80 h-5 w-5 rounded-full grid place-items-center text-[10px] capitalize">
|
|
|
|
{(user.display_name ?? "A")[0]}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<h6 className="text-xs font-medium">{user.display_name}</h6>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<Link href={`/?next_path=${router.asPath}`}>
|
|
|
|
<a>
|
|
|
|
<PrimaryButton className="flex-shrink-0" outline>
|
|
|
|
Sign in
|
|
|
|
</PrimaryButton>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default IssueNavbar;
|