From 814a25d005431be753b96c577ab9dfbe900ce04e Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 22 Jan 2023 21:05:19 -0800 Subject: [PATCH] Unify and finalize optimistic UI updates --- components/CharacterGrid/index.tsx | 13 ++++++++++--- components/SummonGrid/index.tsx | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/components/CharacterGrid/index.tsx b/components/CharacterGrid/index.tsx index 1c55e7dd..d4c72e6e 100644 --- a/components/CharacterGrid/index.tsx +++ b/components/CharacterGrid/index.tsx @@ -274,6 +274,7 @@ const CharacterGrid = (props: Props) => { // Note: Saves, but debouncing is not working properly async function saveUncap(id: string, position: number, uncapLevel: number) { storePreviousUncapValue(position) + storePreviousTranscendenceStage(position) try { if (uncapLevel != previousUncapValues[position]) @@ -285,11 +286,17 @@ const CharacterGrid = (props: Props) => { // Revert optimistic UI updateUncapLevel(position, previousUncapValues[position]) + updateTranscendenceStage(position, previousTranscendenceStages[position]) // Remove optimistic key - let newPreviousValues = { ...previousUncapValues } - delete newPreviousValues[position] - setPreviousUncapValues(newPreviousValues) + let newPreviousTranscendenceStages = { ...previousTranscendenceStages } + let newPreviousUncapValues = { ...previousUncapValues } + + delete newPreviousTranscendenceStages[position] + delete newPreviousUncapValues[position] + + setPreviousTranscendenceStages(newPreviousTranscendenceStages) + setPreviousUncapValues(newPreviousUncapValues) } } diff --git a/components/SummonGrid/index.tsx b/components/SummonGrid/index.tsx index 25f19e61..0da1200e 100644 --- a/components/SummonGrid/index.tsx +++ b/components/SummonGrid/index.tsx @@ -159,6 +159,7 @@ const SummonGrid = (props: Props) => { // Note: Saves, but debouncing is not working properly async function saveUncap(id: string, position: number, uncapLevel: number) { storePreviousUncapValue(position) + storePreviousTranscendenceStage(position) try { if (uncapLevel != previousUncapValues[position]) @@ -170,11 +171,17 @@ const SummonGrid = (props: Props) => { // Revert optimistic UI updateUncapLevel(position, previousUncapValues[position]) + updateTranscendenceStage(position, previousTranscendenceStages[position]) // Remove optimistic key - let newPreviousValues = { ...previousUncapValues } - delete newPreviousValues[position] - setPreviousUncapValues(newPreviousValues) + let newPreviousTranscendenceStages = { ...previousTranscendenceStages } + let newPreviousUncapValues = { ...previousUncapValues } + + delete newPreviousTranscendenceStages[position] + delete newPreviousUncapValues[position] + + setPreviousTranscendenceStages(newPreviousTranscendenceStages) + setPreviousUncapValues(newPreviousUncapValues) } } @@ -192,6 +199,10 @@ const SummonGrid = (props: Props) => { // Optimistically update UI updateUncapLevel(position, uncapLevel) + + if (uncapLevel < 6) { + updateTranscendenceStage(position, 0) + } } } @@ -298,6 +309,10 @@ const SummonGrid = (props: Props) => { // Optimistically update UI updateTranscendenceStage(position, stage) + + if (stage > 0) { + updateUncapLevel(position, 6) + } } }