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

63 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-09-29 12:02:47 +00:00
import { FC } from "react";
import useSWR from "swr";
2023-10-02 15:03:28 +00:00
import { observer } from "mobx-react-lite";
2023-09-29 12:02:47 +00:00
// store
import { useMobxStore } from "lib/mobx/store-provider";
// components
2023-10-02 15:03:28 +00:00
import { CyclesBoard, CyclesList } from "components/cycles";
import { Loader } from "components/ui";
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-10-02 15:03:28 +00:00
workspaceSlug: string;
projectId: string;
2023-09-29 12:02:47 +00:00
}
2023-10-02 15:03:28 +00:00
export const CyclesView: FC<ICyclesView> = observer((props) => {
const { filter, view, workspaceSlug, projectId } = props;
2023-09-29 12:02:47 +00:00
// store
const { cycle: cycleStore } = useMobxStore();
2023-10-02 15:03:28 +00:00
// api call to fetch cycles list
2023-09-29 12:02:47 +00:00
useSWR(
workspaceSlug && projectId ? `CYCLES_LIST_${projectId}` : null,
2023-10-02 15:03:28 +00:00
workspaceSlug && projectId ? () => cycleStore.fetchCycles(workspaceSlug, projectId, filter) : null
2023-09-29 12:02:47 +00:00
);
2023-10-02 15:03:28 +00:00
const cyclesList = cycleStore.cycles?.[projectId]?.[filter];
console.log("cyclesList", cyclesList);
console.log("cyclesList", cyclesList);
return (
<>
2023-10-02 15:03:28 +00:00
{view === "list" && (
<>
{cyclesList ? (
<CyclesList cycles={cyclesList} filter={filter} />
) : (
<Loader className="space-y-4">
<Loader.Item height="50px" />
<Loader.Item height="50px" />
<Loader.Item height="50px" />
</Loader>
)}
</>
)}
{view === "board" && (
<>
{cyclesList ? (
<CyclesBoard cycles={cyclesList} filter={filter} />
) : (
<Loader className="grid grid-cols-1 gap-9 md:grid-cols-2 lg:grid-cols-3">
<Loader.Item height="200px" />
<Loader.Item height="200px" />
<Loader.Item height="200px" />
</Loader>
)}
</>
)}
{view === "gantt" && <CyclesList cycles={cyclesList} filter={filter} />}
</>
);
2023-10-02 15:03:28 +00:00
});