@geekapps/silo-elements-nextjs 0.2.58 → 0.2.60

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.
package/dist/index.js CHANGED
@@ -1280,6 +1280,14 @@ function Video({
1280
1280
  const [storyboardCues, setStoryboardCues] = useState(
1281
1281
  []
1282
1282
  );
1283
+ const [ratingCounts, setRatingCounts] = useState(
1284
+ () => ({ LOVE: parsed.rating?.counts?.LOVE ?? 0, LIKE: parsed.rating?.counts?.LIKE ?? 0, DISLIKE: parsed.rating?.counts?.DISLIKE ?? 0 })
1285
+ );
1286
+ const [userReaction, setUserReaction] = useState(parsed.rating?.userReaction ?? null);
1287
+ const userReactionRef = useRef(userReaction);
1288
+ userReactionRef.current = userReaction;
1289
+ const onReactRef = useRef(parsed.rating?.onReact);
1290
+ onReactRef.current = parsed.rating?.onReact;
1283
1291
  const [preview, setPreview] = useState(null);
1284
1292
  const [duration, setDuration] = useState(0);
1285
1293
  const [currentTime, setCurrentTime] = useState(0);
@@ -2782,23 +2790,34 @@ function Video({
2782
2790
  ] }),
2783
2791
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5 @sm:gap-1", children: [
2784
2792
  parsed.rating && (() => {
2785
- const r = parsed.rating;
2786
- const reactions = [
2793
+ const REACTIONS = [
2787
2794
  { key: "LOVE", emoji: "\u2764\uFE0F" },
2788
2795
  { key: "LIKE", emoji: "\u{1F44D}" },
2789
2796
  { key: "DISLIKE", emoji: "\u{1F44E}" }
2790
2797
  ];
2791
2798
  return /* @__PURE__ */ jsxs(Fragment, { children: [
2792
- reactions.map(({ key, emoji }) => {
2793
- const count = r.counts?.[key] ?? 0;
2794
- const active = r.userReaction === key;
2799
+ REACTIONS.map(({ key, emoji }) => {
2800
+ const count = ratingCounts[key] ?? 0;
2801
+ const active = userReaction === key;
2795
2802
  return /* @__PURE__ */ jsxs(
2796
2803
  "button",
2797
2804
  {
2798
2805
  type: "button",
2799
2806
  onClick: (e) => {
2800
2807
  e.stopPropagation();
2801
- r.onReact?.(active ? null : key);
2808
+ const next = active ? null : key;
2809
+ setUserReaction(next);
2810
+ setRatingCounts((prev) => {
2811
+ const updated = { ...prev };
2812
+ const prev_reaction = userReactionRef.current;
2813
+ if (active) updated[key] = Math.max(0, (updated[key] ?? 0) - 1);
2814
+ else {
2815
+ if (prev_reaction) updated[prev_reaction] = Math.max(0, (updated[prev_reaction] ?? 0) - 1);
2816
+ updated[key] = (updated[key] ?? 0) + 1;
2817
+ }
2818
+ return updated;
2819
+ });
2820
+ onReactRef.current?.(next);
2802
2821
  },
2803
2822
  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"}`,
2804
2823
  "aria-label": key.toLowerCase(),