@upstep/react-native 0.6.7 → 0.6.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upstep/react-native",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "description": "Upstep feedback SDK for React Native",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -81,9 +81,11 @@ export function FeedbackProvider({
81
81
  );
82
82
 
83
83
  const vote = useCallback(async (feedbackId: string, value: VoteValue) => {
84
- // Optimistic update: flip vote + re-sort with a smooth animation
84
+ // Capture snapshot for rollback, then animate into new sorted position
85
+ let snapshot: Feedback[] = [];
85
86
  LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
86
87
  setFeedItems((prev) => {
88
+ snapshot = prev;
87
89
  const updated = prev.map((f) => {
88
90
  if (f.id !== feedbackId) return f;
89
91
  const wasVoted = f.userVote === "UP";
@@ -96,10 +98,14 @@ export function FeedbackProvider({
96
98
  return [...updated].sort((a, b) => b.upvotes - a.upvotes);
97
99
  });
98
100
 
99
- // Confirm with server, then silently sync
100
- await client.vote(feedbackId, value);
101
- await loadFeed();
102
- }, [client, loadFeed]);
101
+ try {
102
+ await client.vote(feedbackId, value);
103
+ } catch {
104
+ // API failed — animate back to original order
105
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
106
+ setFeedItems(snapshot);
107
+ }
108
+ }, [client]);
103
109
 
104
110
  const getItem = useCallback(
105
111
  (feedbackId: string) => client.getItem(feedbackId),