temp
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import SearchBar from "../../components/searchBar";
|
||||
import { getAllActs } from "@/lib/acts/actions";
|
||||
import { CalendarIcon, LandmarkIcon } from "lucide-react";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
|
||||
export const metadata: Metadata = { title: "Acts" };
|
||||
|
||||
export default async function Acts({ searchParams }: { searchParams: Promise<{ q?: string }> }) {
|
||||
const { q } = await searchParams;
|
||||
const user = await getCurrentUser();
|
||||
const acts = await getAllActs();
|
||||
|
||||
const query = q?.trim().toLowerCase() ?? "";
|
||||
|
||||
const filteredActs = query
|
||||
? acts.filter((a) =>
|
||||
`${a.actType.name.toLowerCase()} ${a.title.toLowerCase()} ${a.issuingInstitution.name.toLowerCase()}`.includes(query)
|
||||
)
|
||||
: acts;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between">
|
||||
<h1>Acts</h1>
|
||||
<SearchBar />
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
{user?.isAdmin && (
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
<Link href="/acts/create/"><Button variant="secondary">Create a new act</Button></Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-6">
|
||||
{
|
||||
filteredActs.length > 0 ? filteredActs.map((a) => (
|
||||
<div className="flex flex-col gap-2 md:gap-1" key={a.id}>
|
||||
<Link href={`/acts/${a.id}`} className="max-w-vh">
|
||||
<h3 className="hover:underline underline-offset-8 decoration-2 cursor-pointer truncate">{a.actType.name} {a.numberInSeries && `${a.numberInSeries}/${a.numberYear}`} “{a.title}”</h3>
|
||||
</Link>
|
||||
<div className="flex flex-col md:flex-row gap-0.5 md:gap-8 md:items-center">
|
||||
<p className="flex gap-2 items-center"><LandmarkIcon size={16} /><span className="truncate">{a.issuingInstitution.name}</span></p>
|
||||
<p className="flex gap-2 items-center"><CalendarIcon size={16} />{formatDate(a.createdAt)}</p>
|
||||
</div>
|
||||
</div>
|
||||
)) : <h2 className="text-muted-foreground">There are no acts yet...</h2>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user