feat(web): add chat comments atoms and hooks

This commit is contained in:
CREDO23 2026-01-15 19:57:25 +02:00
parent 33670aceb5
commit 134f9577b9
3 changed files with 163 additions and 0 deletions

View file

@ -0,0 +1,34 @@
import { atomWithQuery } from "jotai-tanstack-query";
import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms";
import { chatCommentsApiService } from "@/lib/apis/chat-comments-api.service";
import { cacheKeys } from "@/lib/query-client/cache-keys";
export const mentionsAtom = atomWithQuery((get) => {
const searchSpaceId = get(activeSearchSpaceIdAtom);
return {
queryKey: cacheKeys.mentions.all(searchSpaceId ? Number(searchSpaceId) : undefined),
staleTime: 60 * 1000, // 1 minute
queryFn: async () => {
return chatCommentsApiService.getMentions({
search_space_id: searchSpaceId ? Number(searchSpaceId) : undefined,
});
},
};
});
export const unreadMentionsAtom = atomWithQuery((get) => {
const searchSpaceId = get(activeSearchSpaceIdAtom);
return {
queryKey: cacheKeys.mentions.unreadOnly(searchSpaceId ? Number(searchSpaceId) : undefined),
staleTime: 30 * 1000, // 30 seconds
queryFn: async () => {
return chatCommentsApiService.getMentions({
search_space_id: searchSpaceId ? Number(searchSpaceId) : undefined,
unread_only: true,
});
},
};
});