fix(socket): add missing article events and notification types

This commit is contained in:
zhenyi 2026-05-31 13:11:51 +08:00
parent 29e6f6214d
commit 879aafa3fa
2 changed files with 37 additions and 3 deletions

View File

@ -1,9 +1,17 @@
import { Bell, Check, ChevronRight } from "lucide-react"; import { Bell, Check, ChevronRight } from "lucide-react";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { client } from "@/client"; import { api } from "@/client";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { useAuth } from "@/context/auth-context"; import { useAuth } from "@/context/auth-context";
interface NotificationItem {
id: string;
title: string;
body: string;
read_at?: string | null;
created_at: string;
}
export default function MeNotificationsPage() { export default function MeNotificationsPage() {
const { me } = useAuth(); const { me } = useAuth();
const unreadCount = me?.has_unread_notifications ?? 0; const unreadCount = me?.has_unread_notifications ?? 0;
@ -11,7 +19,7 @@ export default function MeNotificationsPage() {
const { data: notifications, isLoading } = useQuery({ const { data: notifications, isLoading } = useQuery({
queryKey: ["user", "notifications"], queryKey: ["user", "notifications"],
queryFn: async () => { queryFn: async () => {
const res = await client.userListNotifications(); const res = await api.get<NotificationItem[]>("/api/v1/ws/notifications");
return res.data; return res.data;
}, },
retry: false, retry: false,
@ -40,7 +48,7 @@ export default function MeNotificationsPage() {
<div className="h-16 animate-pulse rounded-lg bg-muted" key={i} /> <div className="h-16 animate-pulse rounded-lg bg-muted" key={i} />
)) ))
) : (notifications ?? []).length > 0 ? ( ) : (notifications ?? []).length > 0 ? (
notifications!.map((notif) => ( notifications!.map((notif: NotificationItem) => (
<div <div
className="flex items-start gap-3 rounded-lg px-4 py-4 transition-colors hover:bg-accent/50 cursor-pointer" className="flex items-start gap-3 rounded-lg px-4 py-4 transition-colors hover:bg-accent/50 cursor-pointer"
key={notif.id} key={notif.id}

View File

@ -547,6 +547,27 @@ export type MessageForwardedService = {
forwarded_at: string; forwarded_at: string;
}; };
// --- Article event service structs ---
export type ArticleLikedService = {
article_id: string;
like_count: number;
};
export type ArticleUnlikedService = {
article_id: string;
like_count: number;
};
export type ArticleCommentCreatedService = {
comment: { article: string };
comment_count: number;
};
export type ArticleCommentDeletedService = {
article_id: string;
comment_count: number;
};
// --- WsOutEvent discriminated union --- // --- WsOutEvent discriminated union ---
export type WsError = { export type WsError = {
type: "error"; type: "error";
@ -603,6 +624,7 @@ export type WsOutEvent =
| { type: "attachment_uploaded"; data: AttachmentUploadedService } | { type: "attachment_uploaded"; data: AttachmentUploadedService }
| { type: "user_banned"; data: BannedService } | { type: "user_banned"; data: BannedService }
| { type: "user_unbanned"; data: UnbannedService } | { type: "user_unbanned"; data: UnbannedService }
| { type: "voice_channel_joined"; data: VoiceChannelJoinedService }
| { type: "voice_channel_left"; data: VoiceChannelLeftService } | { type: "voice_channel_left"; data: VoiceChannelLeftService }
| { type: "conversation_pinned"; room: RoomInfo; data: ConversationPinnedService } | { type: "conversation_pinned"; room: RoomInfo; data: ConversationPinnedService }
| { type: "conversation_unpinned"; room: RoomInfo; data: ConversationUnpinnedService } | { type: "conversation_unpinned"; room: RoomInfo; data: ConversationUnpinnedService }
@ -617,4 +639,8 @@ export type WsOutEvent =
| { type: "message_unstarred"; room: RoomInfo; data: MessageUnstarredService } | { type: "message_unstarred"; room: RoomInfo; data: MessageUnstarredService }
| { type: "starred_list"; data: StarredMessageEntry[] } | { type: "starred_list"; data: StarredMessageEntry[] }
| { type: "message_forwarded"; room: RoomInfo; data: MessageForwardedService } | { type: "message_forwarded"; room: RoomInfo; data: MessageForwardedService }
| { type: "article.liked"; room: RoomInfo; data: ArticleLikedService }
| { type: "article.unliked"; room: RoomInfo; data: ArticleUnlikedService }
| { type: "article.comment.created"; room: RoomInfo; data: ArticleCommentCreatedService }
| { type: "article.comment.deleted"; room: RoomInfo; data: ArticleCommentDeletedService }
| { type: "response"; request_id: string; data: unknown }; | { type: "response"; request_id: string; data: unknown };