2024-05-14 08:56:54 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { FC, useEffect } from "react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-09-04 11:57:29 +00:00
|
|
|
import Image from "next/image";
|
2024-05-16 07:37:47 +00:00
|
|
|
import { useSearchParams } from "next/navigation";
|
2024-05-14 08:56:54 +00:00
|
|
|
import useSWR from "swr";
|
2023-09-01 11:12:30 +00:00
|
|
|
// components
|
2024-06-10 06:46:23 +00:00
|
|
|
import { IssueKanbanLayoutRoot, IssuesListLayoutRoot } from "@/components/issues";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IssueAppliedFilters } from "@/components/issues/filters/applied-filters/root";
|
|
|
|
import { IssuePeekOverview } from "@/components/issues/peek-overview";
|
2024-06-10 06:46:23 +00:00
|
|
|
// hooks
|
|
|
|
import { useIssue, useIssueDetails, useIssueFilter } from "@/hooks/store";
|
|
|
|
// store
|
|
|
|
import { PublishStore } from "@/store/publish/publish.store";
|
2023-09-04 11:57:29 +00:00
|
|
|
// assets
|
|
|
|
import SomethingWentWrongImage from "public/something-went-wrong.svg";
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
type Props = {
|
2024-05-16 07:37:47 +00:00
|
|
|
peekId: string | undefined;
|
2024-06-10 06:46:23 +00:00
|
|
|
publishSettings: PublishStore;
|
2024-05-14 08:56:54 +00:00
|
|
|
};
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
export const IssuesLayoutsRoot: FC<Props> = observer((props) => {
|
|
|
|
const { peekId, publishSettings } = props;
|
2024-05-16 07:37:47 +00:00
|
|
|
// query params
|
2024-06-10 06:46:23 +00:00
|
|
|
const searchParams = useSearchParams();
|
2024-05-16 07:37:47 +00:00
|
|
|
const states = searchParams.get("states") || undefined;
|
|
|
|
const priority = searchParams.get("priority") || undefined;
|
|
|
|
const labels = searchParams.get("labels") || undefined;
|
2024-06-10 06:46:23 +00:00
|
|
|
// store hooks
|
|
|
|
const { getIssueFilters } = useIssueFilter();
|
2024-05-16 13:58:37 +00:00
|
|
|
const { loader, issues, error, fetchPublicIssues } = useIssue();
|
2024-05-14 08:56:54 +00:00
|
|
|
const issueDetailStore = useIssueDetails();
|
2024-06-10 06:46:23 +00:00
|
|
|
// derived values
|
|
|
|
const { anchor } = publishSettings;
|
|
|
|
const issueFilters = anchor ? getIssueFilters(anchor) : undefined;
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
useSWR(
|
2024-06-10 06:46:23 +00:00
|
|
|
anchor ? `PUBLIC_ISSUES_${anchor}` : null,
|
|
|
|
anchor ? () => fetchPublicIssues(anchor, { states, priority, labels }) : null
|
2024-05-16 13:58:37 +00:00
|
|
|
);
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-06-10 06:46:23 +00:00
|
|
|
if (peekId) {
|
2023-09-01 11:12:30 +00:00
|
|
|
issueDetailStore.setPeekId(peekId.toString());
|
|
|
|
}
|
2024-06-10 06:46:23 +00:00
|
|
|
}, [peekId, issueDetailStore]);
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
// derived values
|
|
|
|
const activeLayout = issueFilters?.display_filters?.layout || undefined;
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
if (!anchor) return null;
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
return (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="relative h-full w-full overflow-hidden">
|
2024-06-10 06:46:23 +00:00
|
|
|
{peekId && <IssuePeekOverview anchor={anchor} peekId={peekId} />}
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-05-16 07:37:47 +00:00
|
|
|
{loader && !issues ? (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="py-10 text-center text-sm text-custom-text-100">Loading...</div>
|
2023-09-01 11:12:30 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2024-05-16 07:37:47 +00:00
|
|
|
{error ? (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="grid h-full w-full place-items-center p-6">
|
2023-09-04 11:57:29 +00:00
|
|
|
<div className="text-center">
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="mx-auto grid h-52 w-52 place-items-center rounded-full bg-custom-background-80">
|
|
|
|
<div className="grid h-32 w-32 place-items-center">
|
2023-09-04 11:57:29 +00:00
|
|
|
<Image src={SomethingWentWrongImage} alt="Oops! Something went wrong" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-01 07:55:48 +00:00
|
|
|
<h1 className="mt-12 text-3xl font-semibold">Oops! Something went wrong.</h1>
|
2023-09-04 11:57:29 +00:00
|
|
|
<p className="mt-4 text-custom-text-300">The public board does not exist. Please check the URL.</p>
|
|
|
|
</div>
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2024-05-14 08:56:54 +00:00
|
|
|
activeLayout && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="relative flex h-full w-full flex-col overflow-hidden">
|
2023-12-05 11:56:57 +00:00
|
|
|
{/* applied filters */}
|
2024-06-10 06:46:23 +00:00
|
|
|
<IssueAppliedFilters anchor={anchor} />
|
2023-12-05 11:56:57 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
{activeLayout === "list" && (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="relative h-full w-full overflow-y-auto">
|
2024-06-10 06:46:23 +00:00
|
|
|
<IssuesListLayoutRoot anchor={anchor} />
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2024-05-14 08:56:54 +00:00
|
|
|
{activeLayout === "kanban" && (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="relative mx-auto h-full w-full p-5">
|
2024-06-10 06:46:23 +00:00
|
|
|
<IssueKanbanLayoutRoot anchor={anchor} />
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2023-12-05 11:56:57 +00:00
|
|
|
</div>
|
2023-09-01 11:12:30 +00:00
|
|
|
)
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|