reactions

This commit is contained in:
john 2025-05-28 22:05:51 +02:00
parent 48e7094c5e
commit c21e193fbf
9 changed files with 97 additions and 119 deletions

View file

@ -1,5 +1,6 @@
import { Temporal } from '@js-temporal/polyfill'
import { components } from '../../api/schema.ts'
import { immerable } from 'immer'
export interface EmojiReaction {
emoji: string
@ -8,6 +9,8 @@ export interface EmojiReaction {
}
export class Post {
[immerable] = true
public readonly postId: string
public readonly content: string
public readonly media: PostMedia[]
@ -44,9 +47,9 @@ export class Post {
dto.reactions.map((r) => ({
emoji: r.emoji,
count: r.count,
didReact: r.didReact
didReact: r.didReact,
})),
dto.possibleReactions
dto.possibleReactions,
)
}
}

View file

@ -60,31 +60,23 @@ export class PostsService {
}
async addReaction(postId: string, emoji: string): Promise<void> {
const response = await this.client.POST('/posts/{postId}/reactions', {
await this.client.POST('/posts/{postId}/reactions', {
params: {
path: { postId }
path: { postId },
},
body: { emoji },
credentials: 'include',
})
if (!response.data) {
throw new Error('Failed to add reaction')
}
}
async removeReaction(postId: string, emoji: string): Promise<void> {
const response = await this.client.DELETE('/posts/{postId}/reactions', {
await this.client.DELETE('/posts/{postId}/reactions', {
params: {
path: { postId }
path: { postId },
},
body: { emoji },
credentials: 'include',
})
if (!response.data) {
throw new Error('Failed to remove reaction')
}
}
}