diff --git a/services/frontend/src/features/messages/hooks/useMessages.ts b/services/frontend/src/features/messages/hooks/useMessages.ts index 15cc37e..3740d01 100644 --- a/services/frontend/src/features/messages/hooks/useMessages.ts +++ b/services/frontend/src/features/messages/hooks/useMessages.ts @@ -29,8 +29,9 @@ export function useMessages() { const [cursor, setCursor] = useState(null); const [hasMore, setHasMore] = useState(false); const currentGuild = useRef(null); + const currentChannel = useRef(undefined); - const fetchMessages = useCallback(async (guildId?: string) => { + const fetchMessages = useCallback(async (guildId?: string, channelId?: string) => { if (!guildId) { setMessages([]); setCursor(null); @@ -38,14 +39,15 @@ export function useMessages() { return []; } currentGuild.current = guildId; + currentChannel.current = channelId; setLoading(true); setError(null); try { - const params = new URLSearchParams({ - limit: String(PAGE_SIZE), + const result = await listMessages({ guildId, + channelId, + limit: PAGE_SIZE, }); - const result = await listMessages(params); if (currentGuild.current === guildId) { setMessages(result.data); setCursor(result.nextCursor); @@ -65,12 +67,12 @@ export function useMessages() { if (!cursor || !currentGuild.current || loadingMore) return; setLoadingMore(true); try { - const params = new URLSearchParams({ - limit: String(PAGE_SIZE), + const result = await listMessages({ guildId: currentGuild.current, + channelId: currentChannel.current, cursor, + limit: PAGE_SIZE, }); - const result = await listMessages(params); setMessages((prev) => [...prev, ...result.data]); setCursor(result.nextCursor); setHasMore(!!result.nextCursor); diff --git a/services/frontend/src/shared/api/client.ts b/services/frontend/src/shared/api/client.ts index 90392d0..ce80e8b 100644 --- a/services/frontend/src/shared/api/client.ts +++ b/services/frontend/src/shared/api/client.ts @@ -151,10 +151,19 @@ export type DashboardTab = "live" | "messages" | "analytics"; // ─── Messages ──────────────────────────────────────────────────────────────── -export function listMessages( - params: URLSearchParams, -): Promise> { - return request>(`/api/messages?${params}`); +export function listMessages(params: { + guildId: string; + channelId?: string; + limit?: number; + cursor?: string; +}): Promise> { + const sp = new URLSearchParams({ + guildId: params.guildId, + limit: String(params.limit ?? 100), + ...(params.channelId && { channelId: params.channelId }), + ...(params.cursor && { cursor: params.cursor }), + }); + return request>(`/api/messages?${sp}`); } export function listReview(