@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 +1 -1
- package/src/FeedbackContext.tsx +11 -5
package/package.json
CHANGED
package/src/FeedbackContext.tsx
CHANGED
|
@@ -81,9 +81,11 @@ export function FeedbackProvider({
|
|
|
81
81
|
);
|
|
82
82
|
|
|
83
83
|
const vote = useCallback(async (feedbackId: string, value: VoteValue) => {
|
|
84
|
-
//
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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),
|