Chats: Zähler ungelesener Nachrichten am Chat-Symbol

Damit man neue Nachrichten bemerkt, ohne die Chats zu öffnen. Schlichtes
invertiertes Kästchen mit der Zahl, in TabBar und Seitenleiste; im aktiven
Ziel wieder umgekehrt. Die Zahl kommt aus derselben Abfrage wie die
Gesprächsübersicht (alle 30 s, nach dem Lesen sofort neu), also ohne
eigenen Endpunkt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
This commit is contained in:
irrlicht
2026-10-13 13:20:04 +02:00
co-authored by Claude Opus 5.5
parent f75407ea5b
commit c2fec2555a
6 changed files with 71 additions and 14 deletions
+15 -5
View File
@@ -3,8 +3,9 @@ import { NavLink } from "react-router";
import { Bell, ChartColumn, House, Info, LogOut, MessageSquare, Search, Settings, User } from "lucide-react";
import { api } from "./api";
import { useAuthChanged, useMe } from "./auth";
import { useUnread } from "./chats";
type Target = { title: string; icon?: ReactNode; to: string; end?: boolean };
type Target = { title: string; icon?: ReactNode; to: string; end?: boolean; badge?: number };
// Bereiche, die es noch nicht gibt: Route und Platzhalter-Seite bestehen,
// in der Navigation sind sie bis dahin ausgeblendet.
@@ -18,11 +19,12 @@ export const isReady = (to: string) => !unfinished.has(to);
function useMainTargets(): Target[] {
const me = useMe().data;
const profile = me ? `/u/${encodeURIComponent(me.username)}` : "/me";
const unread = useUnread();
const targets: Target[] = [
{ title: "Feed", icon: <House className="icon" />, to: "/", end: true },
{ title: "Suche", icon: <Search className="icon" />, to: "/search" },
{ title: "Benachrichtigungen", icon: <Bell className="icon" />, to: "/notifications" },
{ title: "Chats", icon: <MessageSquare className="icon" />, to: "/chats" },
{ title: "Chats", icon: <MessageSquare className="icon" />, to: "/chats", badge: unread },
{ title: "Profil", icon: <User className="icon" />, to: profile },
];
return targets.filter((t) => isReady(t.to));
@@ -60,7 +62,7 @@ function TargetList({ targets, onNavigate }: { targets: Target[]; onNavigate: ()
{targets.map((t) => (
<li key={t.title}>
<NavLink to={t.to} end={t.end} onClick={onNavigate}>
{t.icon}<span>{t.title}</span>
{t.icon}<span>{t.title}</span><Badge n={t.badge} />
</NavLink>
</li>
))}
@@ -88,13 +90,21 @@ function Logout({ onDone }: { onDone: () => void }) {
);
}
// Badge: schlichter Zähler hinter dem Symbol, etwa ungelesene Nachrichten.
function Badge({ n }: { n?: number }) {
if (!n) return null;
return <span className="badge" aria-hidden="true">{n > 99 ? "99+" : n}</span>;
}
const label = (t: Target) => (t.badge ? `${t.title} (${t.badge} ungelesen)` : t.title);
// TabBar: mobil unten die (bis zu) fünf wichtigsten Ziele, nur Icons.
export function TabBar() {
return (
<nav id="tabbar" aria-label="Hauptnavigation">
{useMainTargets().map((t) => (
<NavLink key={t.title} to={t.to} end={t.end} aria-label={t.title} title={t.title}>
{t.icon}
<NavLink key={t.title} to={t.to} end={t.end} aria-label={label(t)} title={label(t)}>
{t.icon}<Badge n={t.badge} />
</NavLink>
))}
</nav>