fix(socket): add missing article events and notification types
This commit is contained in:
parent
29e6f6214d
commit
879aafa3fa
@ -1,9 +1,17 @@
|
||||
import { Bell, Check, ChevronRight } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { client } from "@/client";
|
||||
import { api } from "@/client";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
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() {
|
||||
const { me } = useAuth();
|
||||
const unreadCount = me?.has_unread_notifications ?? 0;
|
||||
@ -11,7 +19,7 @@ export default function MeNotificationsPage() {
|
||||
const { data: notifications, isLoading } = useQuery({
|
||||
queryKey: ["user", "notifications"],
|
||||
queryFn: async () => {
|
||||
const res = await client.userListNotifications();
|
||||
const res = await api.get<NotificationItem[]>("/api/v1/ws/notifications");
|
||||
return res.data;
|
||||
},
|
||||
retry: false,
|
||||
@ -40,7 +48,7 @@ export default function MeNotificationsPage() {
|
||||
<div className="h-16 animate-pulse rounded-lg bg-muted" key={i} />
|
||||
))
|
||||
) : (notifications ?? []).length > 0 ? (
|
||||
notifications!.map((notif) => (
|
||||
notifications!.map((notif: NotificationItem) => (
|
||||
<div
|
||||
className="flex items-start gap-3 rounded-lg px-4 py-4 transition-colors hover:bg-accent/50 cursor-pointer"
|
||||
key={notif.id}
|
||||
|
||||
@ -547,6 +547,27 @@ export type MessageForwardedService = {
|
||||
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 ---
|
||||
export type WsError = {
|
||||
type: "error";
|
||||
@ -603,6 +624,7 @@ export type WsOutEvent =
|
||||
| { type: "attachment_uploaded"; data: AttachmentUploadedService }
|
||||
| { type: "user_banned"; data: BannedService }
|
||||
| { type: "user_unbanned"; data: UnbannedService }
|
||||
| { type: "voice_channel_joined"; data: VoiceChannelJoinedService }
|
||||
| { type: "voice_channel_left"; data: VoiceChannelLeftService }
|
||||
| { type: "conversation_pinned"; room: RoomInfo; data: ConversationPinnedService }
|
||||
| { type: "conversation_unpinned"; room: RoomInfo; data: ConversationUnpinnedService }
|
||||
@ -617,4 +639,8 @@ export type WsOutEvent =
|
||||
| { type: "message_unstarred"; room: RoomInfo; data: MessageUnstarredService }
|
||||
| { type: "starred_list"; data: StarredMessageEntry[] }
|
||||
| { 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 };
|
||||
Loading…
Reference in New Issue
Block a user