import { FC, useCallback, useRef } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; 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; }; 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 } = props; // ref const containerRef = useRef(null); const elementRef = useRef(null); // store const { currentProjectDetails } = useProject(); const { currentTab, handleCurrentTab, loader, inboxIssuesArray, 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, callback: fetchNextPages, rootMargin: "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 ? ( ) : (
{inboxIssuesArray.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 && ( )}
)}
); });