"use client"; import { FC, useCallback, useRef, useState } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/navigation"; import { TInboxIssueCurrentTab } from "@plane/types"; import { Loader } from "@plane/ui"; // components import { EmptyState } from "@/components/empty-state"; import { FiltersRoot, InboxIssueAppliedFilters, InboxIssueList } from "@/components/inbox"; import { InboxSidebarLoader } from "@/components/ui"; // constants import { EmptyStateType } from "@/constants/empty-state"; // helpers import { cn } from "@/helpers/common.helper"; import { EInboxIssueCurrentTab } from "@/helpers/inbox.helper"; // hooks import { useProject, useProjectInbox } from "@/hooks/store"; import { useIntersectionObserver } from "@/hooks/use-intersection-observer"; type IInboxSidebarProps = { workspaceSlug: string; projectId: string; setIsMobileSidebar: (value: boolean) => void; }; const tabNavigationOptions: { key: TInboxIssueCurrentTab; label: string }[] = [ { key: EInboxIssueCurrentTab.OPEN, label: "Open", }, { key: EInboxIssueCurrentTab.CLOSED, label: "Closed", }, ]; export const InboxSidebar: FC = observer((props) => { const { workspaceSlug, projectId, setIsMobileSidebar } = props; // ref const containerRef = useRef(null); const [elementRef, setElementRef] = useState(null); // store const { currentProjectDetails } = useProject(); const { currentTab, handleCurrentTab, loader, filteredInboxIssueIds, inboxIssuePaginationInfo, fetchInboxPaginationIssues, getAppliedFiltersCount, } = useProjectInbox(); const router = useRouter(); const fetchNextPages = useCallback(() => { if (!workspaceSlug || !projectId) return; fetchInboxPaginationIssues(workspaceSlug.toString(), projectId.toString()); }, [workspaceSlug, projectId, fetchInboxPaginationIssues]); // page observer useIntersectionObserver(containerRef, elementRef, fetchNextPages, "20%"); return (
{tabNavigationOptions.map((option) => (
{ if (currentTab != option?.key) { handleCurrentTab(option?.key); router.push(`/${workspaceSlug}/projects/${projectId}/inbox?currentTab=${option?.key}`); } }} >
{option?.label}
{option?.key === "open" && currentTab === option?.key && (
{inboxIssuePaginationInfo?.total_results || 0}
)}
))}
{loader != undefined && loader === "filter-loading" && !inboxIssuePaginationInfo?.next_page_results ? ( ) : (
{filteredInboxIssueIds.length > 0 ? ( ) : (
0 ? EmptyStateType.INBOX_SIDEBAR_FILTER_EMPTY_STATE : currentTab === EInboxIssueCurrentTab.OPEN ? EmptyStateType.INBOX_SIDEBAR_OPEN_TAB : EmptyStateType.INBOX_SIDEBAR_CLOSED_TAB } layout="screen-simple" />
)}
{inboxIssuePaginationInfo?.next_page_results && ( )}
)}
); });