import { useEffect, useState } from "react"; import useSWR from "swr"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import isEqual from "lodash/isEqual"; // components import { ActiveCycleInfo } from "components/cycles"; import { Button, ContrastIcon, Spinner } from "@plane/ui"; // services import { CycleService } from "services/cycle.service"; const cycleService = new CycleService(); // constants import { WORKSPACE_ACTIVE_CYCLES_LIST } from "constants/fetch-keys"; // types import { ICycle } from "@plane/types"; const per_page = 3; export const WorkspaceActiveCyclesList = observer(() => { // state const [cursor, setCursor] = useState(`3:0:0`); const [allCyclesData, setAllCyclesData] = useState([]); const [hasMoreResults, setHasMoreResults] = useState(true); // router const router = useRouter(); const { workspaceSlug } = router.query; // fetching active cycles in workspace const { data: workspaceActiveCycles, isLoading } = useSWR( workspaceSlug && cursor ? WORKSPACE_ACTIVE_CYCLES_LIST(workspaceSlug as string, cursor, `${per_page}`) : null, workspaceSlug && cursor ? () => cycleService.workspaceActiveCycles(workspaceSlug.toString(), cursor, per_page) : null ); useEffect(() => { if (workspaceActiveCycles && !isEqual(workspaceActiveCycles.results, allCyclesData)) { setAllCyclesData((prevData) => [...prevData, ...workspaceActiveCycles.results]); setHasMoreResults(workspaceActiveCycles.next_page_results); } }, [workspaceActiveCycles]); const handleLoadMore = () => { if (hasMoreResults) { setCursor(workspaceActiveCycles?.next_cursor); } }; if (allCyclesData.length === 0 && !workspaceActiveCycles) { return (
); } return (
{allCyclesData.length > 0 ? ( <> {workspaceSlug && allCyclesData.map((cycle) => (
))} {hasMoreResults && (
)} ) : (

No ongoing cycles are currently active in any of the projects.

)}
); });