Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/lib/commentsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@ export interface Comment {
parentId: string | null;
heartCount: number;
hearted: boolean;
heartUsers: string[];
canEdit: boolean;
createdAt: string;
replyCount?: number;
replies?: Comment[];
}

export async function fetchComments(clipId: string): Promise<Comment[]> {
export interface ReactionEvent {
emoji: string;
username: string;
createdAt: string;
}

export async function fetchComments(
clipId: string
): Promise<{ comments: Comment[]; reactionEvents: ReactionEvent[] }> {
const res = await fetch(`/api/clips/${clipId}/comments`);
if (res.ok) {
const data = await res.json();
return data.comments;
return { comments: data.comments ?? [], reactionEvents: data.reactionEvents ?? [] };
}
return [];
return { comments: [], reactionEvents: [] };
}

export async function postComment(
Expand All @@ -45,6 +55,26 @@ export async function postComment(
return data.comment;
}

export async function editComment(
clipId: string,
commentId: string,
text: string,
gifUrl?: string
): Promise<{ text: string; gifUrl: string | null }> {
const body: { commentId: string; text: string; gifUrl?: string } = { commentId, text };
if (gifUrl) body.gifUrl = gifUrl;

const res = await fetch(`/api/clips/${clipId}/comments`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});

if (!res.ok) throw new Error('Failed to edit comment');
const data = await res.json();
return data.comment;
}

export async function deleteComment(clipId: string, commentId: string): Promise<string[]> {
const res = await fetch(`/api/clips/${clipId}/comments`, {
method: 'DELETE',
Expand Down
Loading
Loading