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 | undefined; viewType: TViewTypes; viewOperations: TViewOperations; }; export const ViewRoot: FC = observer((props) => { const { workspaceSlug, projectId, viewId, viewType, viewOperations } = 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 = 124; if (!tabContainer || !tabItemViewMore) return; const containerWidth = tabContainer.clientWidth; const itemViewMoreLeftOffset = tabItemViewMore.offsetLeft; const itemViewMoreRightOffset = containerWidth - itemViewMoreLeftOffset; if (itemViewMoreLeftOffset + (tabItemViewMore.clientWidth + 10) > containerWidth) { const itemsToRender = Math.floor(containerWidth / itemWidth); setItemsToRenderViewCount(itemsToRender); } if (itemViewMoreRightOffset > itemWidth + 10) { 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]); return (
{viewStore?.viewIds && viewStore?.viewIds.length > 0 && (
{viewStore?.viewIds?.slice(0, itemsToRenderViewsCount || viewStore?.viewIds.length).map((_viewId) => ( ))}
{viewStore?.viewIds.length <= (itemsToRenderViewsCount || viewStore?.viewIds.length) ? null : (
{viewStore?.viewIds.length - (itemsToRenderViewsCount || viewStore?.viewIds.length)} More...
)}
)}
); });