import { FC, Fragment, useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { Plus } from "lucide-react"; // hooks import { useView } from "hooks/store"; // components import { ViewItem, ViewDropdown } from "../"; // ui import { Button } from "@plane/ui"; // types import { TViewOperations } from "../types"; import { TViewTypes } from "@plane/types"; type TViewRoot = { workspaceSlug: string; projectId: string | undefined; viewId: string; viewType: TViewTypes; viewOperations: TViewOperations; baseRoute: string; }; export const ViewRoot: FC = observer((props) => { const { workspaceSlug, projectId, viewId, viewType, viewOperations, baseRoute } = props; // hooks const viewStore = useView(workspaceSlug, projectId, viewType); // state const [itemsToRenderViewsCount, setItemsToRenderViewCount] = useState(0); useEffect(() => { const handleViewTabsVisibility = () => { const tabContainer = document.getElementById("tab-container"); const tabItemViewMore = document.getElementById("tab-item-view-more"); const itemWidth = 116; if (!tabContainer || !tabItemViewMore) return; const containerWidth = tabContainer.clientWidth; const itemViewMoreLeftOffset = tabItemViewMore.offsetLeft + (tabItemViewMore.clientWidth + 10); const itemViewMoreRightOffset = containerWidth - itemViewMoreLeftOffset; const itemsToRenderLeft = Math.floor(itemViewMoreLeftOffset / itemWidth) || 0; const itemsToRenderRight = Math.floor(itemViewMoreRightOffset / itemWidth) || 0; setItemsToRenderViewCount(itemsToRenderLeft + itemsToRenderRight); }; window.addEventListener("resize", () => handleViewTabsVisibility()); handleViewTabsVisibility(); return () => window.removeEventListener("resize", () => handleViewTabsVisibility()); }, [viewStore?.viewIds]); const viewIds = viewStore?.viewIds?.slice(0, itemsToRenderViewsCount || viewStore?.viewIds.length) || []; if (!viewIds.includes(viewId)) { viewIds.pop(); viewIds.push(viewId); } return (
{viewStore?.viewIds && viewStore?.viewIds.length > 0 && (
{viewIds.map((_viewId) => ( ))}
{viewStore?.viewIds.length <= (itemsToRenderViewsCount || viewStore?.viewIds.length) ? null : (
{viewStore?.viewIds.length - (itemsToRenderViewsCount || viewStore?.viewIds.length)} More...
)}
)}
); });