mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-24 21:38:09 +02:00
refactor: remove read tracking from mentions (prep for notification center)
This commit is contained in:
parent
25eb240539
commit
80e19a52cb
11 changed files with 7 additions and 227 deletions
|
|
@ -4,7 +4,6 @@ import type {
|
|||
CreateCommentRequest,
|
||||
CreateReplyRequest,
|
||||
DeleteCommentRequest,
|
||||
MarkMentionReadRequest,
|
||||
UpdateCommentRequest,
|
||||
} from "@/contracts/types/chat-comments.types";
|
||||
import { chatCommentsApiService } from "@/lib/apis/chat-comments-api.service";
|
||||
|
|
@ -71,39 +70,3 @@ export const deleteCommentMutationAtom = atomWithMutation(() => ({
|
|||
toast.error("Failed to delete comment");
|
||||
},
|
||||
}));
|
||||
|
||||
export const markMentionReadMutationAtom = atomWithMutation(() => ({
|
||||
mutationFn: async (request: MarkMentionReadRequest & { search_space_id?: number }) => {
|
||||
return chatCommentsApiService.markMentionRead(request);
|
||||
},
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.mentions.all(variables.search_space_id),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.mentions.unreadOnly(variables.search_space_id),
|
||||
});
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
console.error("Error marking mention as read:", error);
|
||||
},
|
||||
}));
|
||||
|
||||
export const markAllMentionsReadMutationAtom = atomWithMutation(() => ({
|
||||
mutationFn: async (request: { search_space_id?: number }) => {
|
||||
return chatCommentsApiService.markAllMentionsRead();
|
||||
},
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.mentions.all(variables.search_space_id),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.mentions.unreadOnly(variables.search_space_id),
|
||||
});
|
||||
toast.success("All mentions marked as read");
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
console.error("Error marking all mentions as read:", error);
|
||||
toast.error("Failed to mark mentions as read");
|
||||
},
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -15,17 +15,3 @@ export const mentionsAtom = atomWithQuery((get) => {
|
|||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const unreadMentionsAtom = atomWithQuery((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
|
||||
return {
|
||||
queryKey: cacheKeys.mentions.unreadOnly(searchSpaceId ? Number(searchSpaceId) : undefined),
|
||||
queryFn: async () => {
|
||||
return chatCommentsApiService.getMentions({
|
||||
search_space_id: searchSpaceId ? Number(searchSpaceId) : undefined,
|
||||
unread_only: true,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ export const mentionComment = z.object({
|
|||
|
||||
export const mention = z.object({
|
||||
id: z.number(),
|
||||
read: z.boolean(),
|
||||
created_at: z.string(),
|
||||
comment: mentionComment,
|
||||
context: mentionContext,
|
||||
|
|
@ -116,32 +115,11 @@ export const deleteCommentResponse = z.object({
|
|||
*/
|
||||
export const getMentionsRequest = z.object({
|
||||
search_space_id: z.number().optional(),
|
||||
unread_only: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const getMentionsResponse = z.object({
|
||||
mentions: z.array(mention),
|
||||
unread_count: z.number(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Mark mention as read
|
||||
*/
|
||||
export const markMentionReadRequest = z.object({
|
||||
mention_id: z.number(),
|
||||
});
|
||||
|
||||
export const markMentionReadResponse = z.object({
|
||||
mention_id: z.number(),
|
||||
read: z.boolean(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Mark all mentions as read
|
||||
*/
|
||||
export const markAllMentionsReadResponse = z.object({
|
||||
message: z.string(),
|
||||
count: z.number(),
|
||||
total_count: z.number(),
|
||||
});
|
||||
|
||||
export type Author = z.infer<typeof author>;
|
||||
|
|
@ -162,6 +140,3 @@ export type DeleteCommentRequest = z.infer<typeof deleteCommentRequest>;
|
|||
export type DeleteCommentResponse = z.infer<typeof deleteCommentResponse>;
|
||||
export type GetMentionsRequest = z.infer<typeof getMentionsRequest>;
|
||||
export type GetMentionsResponse = z.infer<typeof getMentionsResponse>;
|
||||
export type MarkMentionReadRequest = z.infer<typeof markMentionReadRequest>;
|
||||
export type MarkMentionReadResponse = z.infer<typeof markMentionReadResponse>;
|
||||
export type MarkAllMentionsReadResponse = z.infer<typeof markAllMentionsReadResponse>;
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@ import {
|
|||
getCommentsResponse,
|
||||
getMentionsRequest,
|
||||
getMentionsResponse,
|
||||
type MarkMentionReadRequest,
|
||||
markAllMentionsReadResponse,
|
||||
markMentionReadRequest,
|
||||
markMentionReadResponse,
|
||||
type UpdateCommentRequest,
|
||||
updateCommentRequest,
|
||||
updateCommentResponse,
|
||||
|
|
@ -127,39 +123,12 @@ class ChatCommentsApiService {
|
|||
if (parsed.data.search_space_id !== undefined) {
|
||||
params.set("search_space_id", String(parsed.data.search_space_id));
|
||||
}
|
||||
if (parsed.data.unread_only !== undefined) {
|
||||
params.set("unread_only", String(parsed.data.unread_only));
|
||||
}
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = queryString ? `/api/v1/mentions?${queryString}` : "/api/v1/mentions";
|
||||
|
||||
return baseApiService.get(url, getMentionsResponse);
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark a mention as read
|
||||
*/
|
||||
markMentionRead = async (request: MarkMentionReadRequest) => {
|
||||
const parsed = markMentionReadRequest.safeParse(request);
|
||||
|
||||
if (!parsed.success) {
|
||||
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.put(
|
||||
`/api/v1/mentions/${parsed.data.mention_id}/read`,
|
||||
markMentionReadResponse
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark all mentions as read
|
||||
*/
|
||||
markAllMentionsRead = async () => {
|
||||
return baseApiService.put("/api/v1/mentions/read-all", markAllMentionsReadResponse);
|
||||
};
|
||||
}
|
||||
|
||||
export const chatCommentsApiService = new ChatCommentsApiService();
|
||||
|
|
|
|||
|
|
@ -77,6 +77,5 @@ export const cacheKeys = {
|
|||
},
|
||||
mentions: {
|
||||
all: (searchSpaceId?: number) => ["mentions", searchSpaceId] as const,
|
||||
unreadOnly: (searchSpaceId?: number) => ["mentions", "unread", searchSpaceId] as const,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue