import { FC, ReactNode, useEffect, useState } from "react"; import { useRouter } from "next/router"; import { Maximize2, ArrowRight, Link, Trash, PanelRightOpen, Square, SquareCode } from "lucide-react"; import { observer } from "mobx-react-lite"; // components import { PeekOverviewIssueDetails } from "./issue-detail"; import { PeekOverviewProperties } from "./properties"; // types import { IIssue } from "types"; import { RootStore } from "store/root"; // hooks import { useMobxStore } from "lib/mobx/store-provider"; interface IIssueView { workspaceSlug: string; projectId: string; issueId: string; issueUpdate: (issue: Partial) => void; states: any; members: any; priorities: any; children: ReactNode; } type TPeekModes = "side-peek" | "modal" | "full-screen"; const peekOptions: { key: TPeekModes; icon: any; title: string }[] = [ { key: "side-peek", icon: PanelRightOpen, title: "Side Peek", }, { key: "modal", icon: Square, title: "Modal", }, { key: "full-screen", icon: SquareCode, title: "Full Screen", }, ]; export const IssueView: FC = observer((props) => { const { workspaceSlug, projectId, issueId, issueUpdate, states, members, priorities, children } = props; const router = useRouter(); const { peekIssueId } = router.query as { peekIssueId: string }; const { issueDetail: issueDetailStore }: RootStore = useMobxStore(); const [peekMode, setPeekMode] = useState("side-peek"); const handlePeekMode = (_peek: TPeekModes) => { if (peekMode != _peek) setPeekMode(_peek); }; const updateRoutePeekId = () => { if (issueId != peekIssueId) { const { query } = router; router.push({ pathname: router.pathname, query: { ...query, peekIssueId: issueId }, }); } }; const removeRoutePeekId = () => { const { query } = router; if (query.peekIssueId) { delete query.peekIssueId; router.push({ pathname: router.pathname, query: { ...query }, }); } }; const redirectToIssueDetail = () => { router.push({ pathname: `/${workspaceSlug}/projects/${projectId}/issues/${issueId}`, }); }; useEffect(() => { if (workspaceSlug && projectId && issueId && peekIssueId && issueId === peekIssueId) issueDetailStore.fetchIssueDetails(workspaceSlug, projectId, issueId); }, [workspaceSlug, projectId, issueId, peekIssueId, issueDetailStore]); const issue = issueDetailStore.getIssue; return (
{children}
{issueId === peekIssueId && (
{/* header */}
{peekOptions.map((_option) => (
handlePeekMode(_option?.key)} > <_option.icon width={14} strokeWidth={2} />
{_option?.title}
))}
Subscribe
{/* content */}
{issueDetailStore?.loader && !issue ? (
Loading...
) : ( issue && ( <> {["side-peek", "modal"].includes(peekMode) ? (
{/* reactions */} {/* activity */}
) : (
{/* reactions */} {/* activity */}
)} ) )}
)}
); });