Files
BRETT/app/composables/useLiveComments.ts
T
2026-10-03 20:07:49 +02:00

25 lines
639 B
TypeScript

import type { CommentAttachment } from '~~/shared/utils/attachments'
export interface LiveComment {
id: number
content: string
createdAt: string
userName: string
userId: number
userColor: string | null
userAvatarUrl: string | null
uploadId: string
attachments?: CommentAttachment[]
}
export function useLiveComments() {
const liveComments = useState<LiveComment[]>('comments:live', () => [])
function pushLive(comment: LiveComment) {
if (liveComments.value.some(c => c.id === comment.id)) return
liveComments.value = [comment, ...liveComments.value].slice(0, 50)
}
return { liveComments, pushLive }
}