From 2e50e488a3e408bc1ce3733274f3081512eca166 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Tue, 13 Apr 2021 11:20:31 +0200 Subject: [PATCH] bugfix optimistic insert item at index --- client/src/features/editors/list/EventListWrapper.jsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/client/src/features/editors/list/EventListWrapper.jsx b/client/src/features/editors/list/EventListWrapper.jsx index 3bcfc46e5..92de1508b 100644 --- a/client/src/features/editors/list/EventListWrapper.jsx +++ b/client/src/features/editors/list/EventListWrapper.jsx @@ -30,10 +30,13 @@ export default function EventListWrapper() { const previousEvents = queryClient.getQueryData(eventsNamespace); // optimistically update object, temp ID until refetch - queryClient.setQueryData(eventsNamespace, (old) => [ - ...old, - { ...newEvent, id: new Date().toISOString() }, - ]); + + queryClient.setQueryData(eventsNamespace, (old) => + old.splice(newEvent.order, 0, { + ...newEvent, + id: new Date().toISOString(), + }) + ); // Return a context with the previous and new todo return { previousEvents };