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"; // 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: "open", label: "Open", }, { key: "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, isLoading, 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`); }} >
{option?.label}
{option?.key === "open" && currentTab === option?.key && (
{inboxIssuePaginationInfo?.total_results || 0}
)}
))}
{isLoading === "filter-loading" && !inboxIssuePaginationInfo?.next_page_results ? ( ) : (
{inboxIssuesArray.length > 0 ? ( ) : (
0 ? EmptyStateType.INBOX_SIDEBAR_FILTER_EMPTY_STATE : currentTab === "open" ? EmptyStateType.INBOX_SIDEBAR_OPEN_TAB : EmptyStateType.INBOX_SIDEBAR_CLOSED_TAB } layout="screen-simple" />
)}
{inboxIssuePaginationInfo?.next_page_results && ( )}
)}
); });