Benachrichtigungen: Antworten auf eigene Beiträge

Bisher erfuhr man nur durch Nachsehen, ob jemand geantwortet hat. Jetzt
legt jede Antwort eine Benachrichtigung für den Autor des Elternbeitrags an
(Zeit, Typ, Text mit Auszug, interner Link, gesehen-Flag). Die Glocke in
der Navigation zählt die ungesehenen; die Liste markiert beim Ansehen alles
als gesehen.

Der Auszug zitiert die Antwort, deshalb hängt die Benachrichtigung an deren
pid: Bearbeiten zieht den Text nach, Löschen (auch des Kontos) nimmt sie mit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 21:14:54 +01:00
co-authored by Claude Opus 5.5
parent bed563d369
commit d6b6baedc1
13 changed files with 349 additions and 13 deletions
+4 -2
View File
@@ -4,13 +4,14 @@ import { Bell, ChartColumn, House, Info, LogOut, MessageSquare, Search, Settings
import { api } from "./api";
import { useAuthChanged, useMe } from "./auth";
import { useUnread } from "./chats";
import { useUnreadNotifications } from "./notifications";
import { lockKeyring } from "./keyring";
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.
const unfinished = new Set(["/notifications"]);
const unfinished = new Set<string>();
export const isReady = (to: string) => !unfinished.has(to);
@@ -21,10 +22,11 @@ function useMainTargets(): Target[] {
const me = useMe().data;
const profile = me ? `/u/${encodeURIComponent(me.handle)}` : "/me";
const unread = useUnread();
const unseen = useUnreadNotifications();
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: "Benachrichtigungen", icon: <Bell className="icon" />, to: "/notifications", badge: unseen },
{ title: "Chats", icon: <MessageSquare className="icon" />, to: "/chats", badge: unread },
{ title: "Profil", icon: <User className="icon" />, to: profile },
];
+1
View File
@@ -21,6 +21,7 @@
<li>Helles Design: Hintergrund in warmem Off-White statt reinem Weiß, angenehmer zu lesen</li>
<li>Beiträge und Chats: Anzeigename und @handle stehen zweizeilig neben dem Profilbild</li>
<li>Beiträge und Chats: Das Datum steht jetzt rechts in der Kopfzeile</li>
<li>Neu: Benachrichtigungen. Antwortet jemand auf deinen Beitrag, zählt die Glocke in der Navigation mit; ein Klick auf die Meldung führt zur Antwort</li>
</ul>
<h3>07.11.2026</h3>
<ul>
+3 -2
View File
@@ -9,7 +9,8 @@ import { EntryPage } from "./pages/EntryPage";
import { UserPage } from "./pages/UserPage";
import { StatsPage } from "./pages/StatsPage";
import { ResetPage } from "./pages/ResetPage";
import { MePage, Placeholder } from "./pages/Placeholder";
import { MePage } from "./pages/Placeholder";
import { NotificationsPage } from "./pages/NotificationsPage";
import { DocPage } from "./pages/DocPage";
import { SettingsPage } from "./pages/SettingsPage";
import { KeysPage } from "./pages/KeysPage";
@@ -46,7 +47,7 @@ const router = createBrowserRouter([
{ path: "/reset", element: <ResetPage /> },
{ path: "/me", element: <MePage /> },
{ path: "/search", element: <SearchPage /> },
{ path: "/notifications", element: <Placeholder title="Benachrichtigungen" /> },
{ path: "/notifications", element: <NotificationsPage /> },
{ path: "/chats", element: <ChatsPage /> },
{ path: "/chats/:handle", element: <ChatPage /> },
{ path: "/settings", element: <SettingsPage /> },
+48
View File
@@ -0,0 +1,48 @@
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { api } from "./api";
import { useMe } from "./auth";
// Benachrichtigungen (notes/api.md): der Zähler am Glocken-Icon fragt
// angemeldet alle 30 Sekunden nach; die Liste markiert beim Abruf alles als
// gesehen, danach steht der Zähler sofort auf 0.
export type Notification = {
id: number;
kind: "reply";
message: string;
// Interner Pfad, etwa /e/123.
link: string;
created_at: number;
// Stand vor dem Abruf: false = neu.
seen: boolean;
};
const pollUnread = 30_000;
export function useUnreadNotifications() {
const me = useMe().data;
return (
useQuery({
queryKey: ["notifications", "unread"],
queryFn: async () => (await api.get<{ unread: number }>("/notifications/unread")).unread,
enabled: !!me,
refetchInterval: pollUnread,
}).data ?? 0
);
}
export function useNotifications() {
const me = useMe().data;
const qc = useQueryClient();
return useQuery({
queryKey: ["notifications", "list"],
queryFn: async () => {
const list = (await api.get<{ notifications: Notification[] }>("/notifications")).notifications;
qc.setQueryData(["notifications", "unread"], 0);
return list;
},
enabled: !!me,
// Jeder Besuch der Seite gilt als Ansehen.
staleTime: 0,
});
}
+38
View File
@@ -0,0 +1,38 @@
import { Link } from "react-router";
import { errMsg } from "../api";
import { useMe } from "../auth";
import { AuthBox } from "../components/AuthBox";
import { formatTime } from "../format";
import { useNotifications } from "../notifications";
// NotificationsPage listet die jüngsten Benachrichtigungen; ein Klick führt
// zum Beitrag. Was beim Öffnen noch ungesehen war, steht fett.
export function NotificationsPage() {
const me = useMe();
return (
<>
<section id="notifications">
<h2>Benachrichtigungen</h2>
{me.data && <NotificationList />}
</section>
{me.isSuccess && !me.data && <AuthBox />}
</>
);
}
function NotificationList() {
const list = useNotifications();
if (list.isError) return <p className="msg">{errMsg(list.error, "Benachrichtigungen konnten nicht geladen werden.")}</p>;
if (list.data?.length === 0) return <p className="muted">Noch keine Benachrichtigungen.</p>;
return (
<ul id="notification-list">
{list.data?.map((n) => (
<li key={n.id}>
<Link to={n.link}>{n.seen ? n.message : <strong>{n.message}</strong>}</Link>
<br />
<span className="muted">{formatTime(n.created_at)}</span>
</li>
))}
</ul>
);
}
+2 -2
View File
@@ -2,8 +2,8 @@ import { Navigate } from "react-router";
import { useMe } from "../auth";
import { AuthBox } from "../components/AuthBox";
// Placeholder steht für Bereiche, die noch eigene Projekte sind
// (Benachrichtigungen).
// Placeholder steht für Bereiche, die noch eigene Projekte sind (siehe
// unfinished in Nav.tsx).
export function Placeholder({ title }: { title: string }) {
return (
<section>