@geekapps/silo-elements-nextjs 0.2.57 → 0.2.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,6 +153,12 @@ function Video({
153
153
  const [storyboardCues, setStoryboardCues] = useState(
154
154
  []
155
155
  );
156
+ const [ratingCounts, setRatingCounts] = useState(
157
+ () => ({ LOVE: parsed.rating?.counts?.LOVE ?? 0, LIKE: parsed.rating?.counts?.LIKE ?? 0, DISLIKE: parsed.rating?.counts?.DISLIKE ?? 0 })
158
+ );
159
+ const [userReaction, setUserReaction] = useState(parsed.rating?.userReaction ?? null);
160
+ const onReactRef = useRef(parsed.rating?.onReact);
161
+ onReactRef.current = parsed.rating?.onReact;
156
162
  const [preview, setPreview] = useState(null);
157
163
  const [duration, setDuration] = useState(0);
158
164
  const [currentTime, setCurrentTime] = useState(0);
@@ -1655,23 +1661,33 @@ function Video({
1655
1661
  ] }),
1656
1662
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5 @sm:gap-1", children: [
1657
1663
  parsed.rating && (() => {
1658
- const r = parsed.rating;
1659
- const reactions = [
1664
+ const REACTIONS = [
1660
1665
  { key: "LOVE", emoji: "\u2764\uFE0F" },
1661
1666
  { key: "LIKE", emoji: "\u{1F44D}" },
1662
1667
  { key: "DISLIKE", emoji: "\u{1F44E}" }
1663
1668
  ];
1664
1669
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1665
- reactions.map(({ key, emoji }) => {
1666
- const count = r.counts?.[key] ?? 0;
1667
- const active = r.userReaction === key;
1670
+ REACTIONS.map(({ key, emoji }) => {
1671
+ const count = ratingCounts[key] ?? 0;
1672
+ const active = userReaction === key;
1668
1673
  return /* @__PURE__ */ jsxs(
1669
1674
  "button",
1670
1675
  {
1671
1676
  type: "button",
1672
1677
  onClick: (e) => {
1673
1678
  e.stopPropagation();
1674
- r.onReact?.(active ? null : key);
1679
+ const next = active ? null : key;
1680
+ setUserReaction(next);
1681
+ setRatingCounts((prev) => {
1682
+ const updated = { ...prev };
1683
+ if (active) updated[key] = Math.max(0, (updated[key] ?? 0) - 1);
1684
+ else {
1685
+ if (userReaction) updated[userReaction] = Math.max(0, (updated[userReaction] ?? 0) - 1);
1686
+ updated[key] = (updated[key] ?? 0) + 1;
1687
+ }
1688
+ return updated;
1689
+ });
1690
+ onReactRef.current?.(next);
1675
1691
  },
1676
1692
  className: `flex items-center gap-0.5 rounded px-1.5 py-1 text-[11px] transition hover:bg-white/10 ${active ? "opacity-100" : "opacity-50 hover:opacity-80"}`,
1677
1693
  "aria-label": key.toLowerCase(),