"use client"; import { useState, useTransition } from "react"; import { Bell, FileText, Megaphone } from "lucide-react"; import { markAnnouncementRead } from "@/actions/announcements"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { MarkdownContent } from "@/components/markdown-content"; export type NewsTickerItemDto = { id: string; title: string; content: string; createdAt: string; authorName: string; isUnread: boolean; attachments: { id: string; fileName: string; fileUrl: string; fileType: string; }[]; }; export function NewsTicker({ items }: { items: NewsTickerItemDto[] }) { const [selected, setSelected] = useState(null); const [readIds, setReadIds] = useState>(new Set()); const [, startTransition] = useTransition(); if (items.length === 0) { return null; } function openAnnouncement(item: NewsTickerItemDto) { setSelected(item); if (!item.isUnread || readIds.has(item.id)) return; setReadIds((current) => new Set(current).add(item.id)); startTransition(async () => { await markAnnouncementRead(item.id); }); } return ( <>
Schwarzes Brett Die neuesten offiziellen Ankündigungen deiner Kita.
{items.length}
{items.map((item) => { const isUnread = item.isUnread && !readIds.has(item.id); return ( ); })}
!open && setSelected(null)}> {selected && ( <> {selected.title} {selected.createdAt} · {selected.authorName}
{selected.attachments.length > 0 && (

Anhänge

{selected.attachments.map((attachment) => ( ))}
)} )}
); }