107 lines
3.8 KiB
TypeScript
107 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import Link from "next/link";
|
|
import { NotebookTextIcon, PenLineIcon } from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { DraftBadge } from "@/components/frontend/story/DraftBadge";
|
|
import {
|
|
EMPTY_JOURNAL_DRAFT,
|
|
JournalFormDialog,
|
|
type MissionOption,
|
|
} from "./JournalFormDialog";
|
|
|
|
export interface JournalCard {
|
|
id: number;
|
|
title: string;
|
|
status: "draft" | "published";
|
|
authorName: string;
|
|
dateLabel: string | null;
|
|
missionLabel: string | null;
|
|
excerpt: string;
|
|
}
|
|
|
|
interface JournalsListProps {
|
|
journals: JournalCard[];
|
|
missions: MissionOption[];
|
|
}
|
|
|
|
export function JournalsList({ journals, missions }: JournalsListProps) {
|
|
const [composing, setComposing] = React.useState(false);
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6">
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<div>
|
|
<p className="text-xs uppercase tracking-[0.3em] text-muted-foreground">
|
|
Member Journals
|
|
</p>
|
|
<h1 className="mt-1 font-serif text-3xl font-bold">Journals</h1>
|
|
<p className="mt-1 max-w-xl text-sm text-muted-foreground">
|
|
First-person accounts from the unit: after-action notes, deployment diaries, and
|
|
everything in between. Write your own at any time; publish when you are happy with it.
|
|
</p>
|
|
</div>
|
|
<Button onClick={() => setComposing(true)}>
|
|
<PenLineIcon className="mr-2 size-4" />
|
|
Write entry
|
|
</Button>
|
|
</div>
|
|
|
|
{journals.length === 0 ? (
|
|
<Card>
|
|
<CardContent className="flex flex-col items-center gap-3 py-12 text-center">
|
|
<NotebookTextIcon className="size-8 text-muted-foreground" />
|
|
<p className="text-muted-foreground">
|
|
No journal entries yet. Be the first to write one.
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
) : (
|
|
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
|
{journals.map((journal) => (
|
|
<Link key={journal.id} href={`/journals/${journal.id}`} className="group">
|
|
<Card className="h-full transition-colors group-hover:border-primary/50">
|
|
<CardContent className="flex h-full flex-col gap-2 p-5">
|
|
<div className="flex items-center gap-2">
|
|
{journal.status === "draft" && <DraftBadge />}
|
|
{journal.missionLabel && (
|
|
<Badge variant="secondary" className="max-w-[60%] truncate text-[10px]">
|
|
{journal.missionLabel}
|
|
</Badge>
|
|
)}
|
|
</div>
|
|
<h2 className="font-serif text-lg font-semibold leading-snug line-clamp-2">
|
|
{journal.title}
|
|
</h2>
|
|
{journal.excerpt && (
|
|
<p className="text-sm text-muted-foreground line-clamp-3">{journal.excerpt}</p>
|
|
)}
|
|
<div className="mt-auto flex items-center gap-2 pt-2 text-xs text-muted-foreground">
|
|
<span className="truncate">{journal.authorName}</span>
|
|
{journal.dateLabel && (
|
|
<>
|
|
<span className="text-border">|</span>
|
|
<span className="shrink-0">{journal.dateLabel}</span>
|
|
</>
|
|
)}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<JournalFormDialog
|
|
open={composing}
|
|
onOpenChange={setComposing}
|
|
missions={missions}
|
|
draft={EMPTY_JOURNAL_DRAFT}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|