@geekapps/silo-elements-nextjs 0.2.59 → 0.2.61

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
@@ -1284,6 +1284,22 @@ function Video({
1284
1284
  () => ({ LOVE: parsed.rating?.counts?.LOVE ?? 0, LIKE: parsed.rating?.counts?.LIKE ?? 0, DISLIKE: parsed.rating?.counts?.DISLIKE ?? 0 })
1285
1285
  );
1286
1286
  const [userReaction, setUserReaction] = useState(parsed.rating?.userReaction ?? null);
1287
+ const userReactionRef = useRef(userReaction);
1288
+ userReactionRef.current = userReaction;
1289
+ const ratingInitializedRef = useRef(false);
1290
+ const incomingCounts = parsed.rating?.counts;
1291
+ const incomingUserReaction = parsed.rating?.userReaction;
1292
+ useEffect(() => {
1293
+ if (ratingInitializedRef.current) return;
1294
+ if (!incomingCounts && incomingUserReaction === void 0) return;
1295
+ ratingInitializedRef.current = true;
1296
+ if (incomingCounts) {
1297
+ setRatingCounts({ LOVE: incomingCounts.LOVE ?? 0, LIKE: incomingCounts.LIKE ?? 0, DISLIKE: incomingCounts.DISLIKE ?? 0 });
1298
+ }
1299
+ if (incomingUserReaction !== void 0) {
1300
+ setUserReaction(incomingUserReaction ?? null);
1301
+ }
1302
+ }, [incomingCounts?.LOVE, incomingCounts?.LIKE, incomingCounts?.DISLIKE, incomingUserReaction]);
1287
1303
  const onReactRef = useRef(parsed.rating?.onReact);
1288
1304
  onReactRef.current = parsed.rating?.onReact;
1289
1305
  const [preview, setPreview] = useState(null);
@@ -2807,9 +2823,10 @@ function Video({
2807
2823
  setUserReaction(next);
2808
2824
  setRatingCounts((prev) => {
2809
2825
  const updated = { ...prev };
2826
+ const prev_reaction = userReactionRef.current;
2810
2827
  if (active) updated[key] = Math.max(0, (updated[key] ?? 0) - 1);
2811
2828
  else {
2812
- if (userReaction) updated[userReaction] = Math.max(0, (updated[userReaction] ?? 0) - 1);
2829
+ if (prev_reaction) updated[prev_reaction] = Math.max(0, (updated[prev_reaction] ?? 0) - 1);
2813
2830
  updated[key] = (updated[key] ?? 0) + 1;
2814
2831
  }
2815
2832
  return updated;