import { _ } from '@evershop/evershop/lib/locale/translate/_'; import axios from 'axios'; import React from 'react'; export interface ReactionCount { type: string; count: number; reacted: boolean; } const EMOJI: Record = { like: '👍', love: '❤️', clap: '👏', insightful: '💡' }; export function ReactionBar({ postUuid, reactions: initial }: { postUuid: string; reactions?: ReactionCount[]; }) { const [reactions, setReactions] = React.useState( initial || [] ); const [busy, setBusy] = React.useState(false); const react = async (type: string) => { if (busy) return; setBusy(true); try { const res = await axios.post(`/api/blog/posts/${postUuid}/react`, { type }); const data = res.data?.data; if (data) { const counts = data.counts || {}; setReactions((prev) => prev.map((r) => ({ ...r, count: counts[r.type] ?? 0, reacted: r.type === data.reacted })) ); } } finally { setBusy(false); } }; if (reactions.length === 0) { return null; } return (
{_('React')}: {reactions.map((r) => ( ))}
); }