@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.
@@ -157,6 +157,22 @@ function Video({
157
157
  () => ({ LOVE: parsed.rating?.counts?.LOVE ?? 0, LIKE: parsed.rating?.counts?.LIKE ?? 0, DISLIKE: parsed.rating?.counts?.DISLIKE ?? 0 })
158
158
  );
159
159
  const [userReaction, setUserReaction] = useState(parsed.rating?.userReaction ?? null);
160
+ const userReactionRef = useRef(userReaction);
161
+ userReactionRef.current = userReaction;
162
+ const ratingInitializedRef = useRef(false);
163
+ const incomingCounts = parsed.rating?.counts;
164
+ const incomingUserReaction = parsed.rating?.userReaction;
165
+ useEffect(() => {
166
+ if (ratingInitializedRef.current) return;
167
+ if (!incomingCounts && incomingUserReaction === void 0) return;
168
+ ratingInitializedRef.current = true;
169
+ if (incomingCounts) {
170
+ setRatingCounts({ LOVE: incomingCounts.LOVE ?? 0, LIKE: incomingCounts.LIKE ?? 0, DISLIKE: incomingCounts.DISLIKE ?? 0 });
171
+ }
172
+ if (incomingUserReaction !== void 0) {
173
+ setUserReaction(incomingUserReaction ?? null);
174
+ }
175
+ }, [incomingCounts?.LOVE, incomingCounts?.LIKE, incomingCounts?.DISLIKE, incomingUserReaction]);
160
176
  const onReactRef = useRef(parsed.rating?.onReact);
161
177
  onReactRef.current = parsed.rating?.onReact;
162
178
  const [preview, setPreview] = useState(null);
@@ -1680,9 +1696,10 @@ function Video({
1680
1696
  setUserReaction(next);
1681
1697
  setRatingCounts((prev) => {
1682
1698
  const updated = { ...prev };
1699
+ const prev_reaction = userReactionRef.current;
1683
1700
  if (active) updated[key] = Math.max(0, (updated[key] ?? 0) - 1);
1684
1701
  else {
1685
- if (userReaction) updated[userReaction] = Math.max(0, (updated[userReaction] ?? 0) - 1);
1702
+ if (prev_reaction) updated[prev_reaction] = Math.max(0, (updated[prev_reaction] ?? 0) - 1);
1686
1703
  updated[key] = (updated[key] ?? 0) + 1;
1687
1704
  }
1688
1705
  return updated;