plane/web/components/cycles/cycles-view.tsx

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-05-28 20:44:40 +00:00
import { useRouter } from "next/router";
2023-09-29 12:02:47 +00:00
import { FC } from "react";
import useSWR from "swr";
// store
import { useMobxStore } from "lib/mobx/store-provider";
// components
2023-09-29 12:02:47 +00:00
import { CyclesList } from "components/cycles";
2023-05-28 20:44:40 +00:00
2023-09-29 12:02:47 +00:00
export interface ICyclesView {
filter: "all" | "current" | "upcoming" | "draft" | "completed" | "incomplete";
view: "list" | "board" | "gantt";
}
2023-09-29 12:02:47 +00:00
export const CyclesView: FC<ICyclesView> = (props) => {
const { filter, view } = props;
// router
2023-05-28 20:44:40 +00:00
const router = useRouter();
const { workspaceSlug, projectId } = router.query;
2023-09-29 12:02:47 +00:00
// store
const { cycle: cycleStore } = useMobxStore();
useSWR(
workspaceSlug && projectId ? `CYCLES_LIST_${projectId}` : null,
workspaceSlug && projectId
? () => cycleStore.fetchCycles(workspaceSlug.toString(), projectId.toString(), filter)
: null
);
if (!projectId) {
return <></>;
}
return (
<>
2023-09-29 12:02:47 +00:00
{view === "list" && <CyclesList cycles={cycleStore.cycles[projectId?.toString()]} />}
{view === "board" && <CyclesList cycles={cycleStore.cycles[projectId?.toString()]} />}
{view === "gantt" && <CyclesList cycles={cycleStore.cycles[projectId?.toString()]} />}
</>
);
};