Unify and finalize optimistic UI updates

This commit is contained in:
Justin Edmund 2023-01-22 21:05:19 -08:00
parent 971f04e88f
commit 814a25d005
2 changed files with 28 additions and 6 deletions

View file

@ -274,6 +274,7 @@ const CharacterGrid = (props: Props) => {
// Note: Saves, but debouncing is not working properly // Note: Saves, but debouncing is not working properly
async function saveUncap(id: string, position: number, uncapLevel: number) { async function saveUncap(id: string, position: number, uncapLevel: number) {
storePreviousUncapValue(position) storePreviousUncapValue(position)
storePreviousTranscendenceStage(position)
try { try {
if (uncapLevel != previousUncapValues[position]) if (uncapLevel != previousUncapValues[position])
@ -285,11 +286,17 @@ const CharacterGrid = (props: Props) => {
// Revert optimistic UI // Revert optimistic UI
updateUncapLevel(position, previousUncapValues[position]) updateUncapLevel(position, previousUncapValues[position])
updateTranscendenceStage(position, previousTranscendenceStages[position])
// Remove optimistic key // Remove optimistic key
let newPreviousValues = { ...previousUncapValues } let newPreviousTranscendenceStages = { ...previousTranscendenceStages }
delete newPreviousValues[position] let newPreviousUncapValues = { ...previousUncapValues }
setPreviousUncapValues(newPreviousValues)
delete newPreviousTranscendenceStages[position]
delete newPreviousUncapValues[position]
setPreviousTranscendenceStages(newPreviousTranscendenceStages)
setPreviousUncapValues(newPreviousUncapValues)
} }
} }

View file

@ -159,6 +159,7 @@ const SummonGrid = (props: Props) => {
// Note: Saves, but debouncing is not working properly // Note: Saves, but debouncing is not working properly
async function saveUncap(id: string, position: number, uncapLevel: number) { async function saveUncap(id: string, position: number, uncapLevel: number) {
storePreviousUncapValue(position) storePreviousUncapValue(position)
storePreviousTranscendenceStage(position)
try { try {
if (uncapLevel != previousUncapValues[position]) if (uncapLevel != previousUncapValues[position])
@ -170,11 +171,17 @@ const SummonGrid = (props: Props) => {
// Revert optimistic UI // Revert optimistic UI
updateUncapLevel(position, previousUncapValues[position]) updateUncapLevel(position, previousUncapValues[position])
updateTranscendenceStage(position, previousTranscendenceStages[position])
// Remove optimistic key // Remove optimistic key
let newPreviousValues = { ...previousUncapValues } let newPreviousTranscendenceStages = { ...previousTranscendenceStages }
delete newPreviousValues[position] let newPreviousUncapValues = { ...previousUncapValues }
setPreviousUncapValues(newPreviousValues)
delete newPreviousTranscendenceStages[position]
delete newPreviousUncapValues[position]
setPreviousTranscendenceStages(newPreviousTranscendenceStages)
setPreviousUncapValues(newPreviousUncapValues)
} }
} }
@ -192,6 +199,10 @@ const SummonGrid = (props: Props) => {
// Optimistically update UI // Optimistically update UI
updateUncapLevel(position, uncapLevel) updateUncapLevel(position, uncapLevel)
if (uncapLevel < 6) {
updateTranscendenceStage(position, 0)
}
} }
} }
@ -298,6 +309,10 @@ const SummonGrid = (props: Props) => {
// Optimistically update UI // Optimistically update UI
updateTranscendenceStage(position, stage) updateTranscendenceStage(position, stage)
if (stage > 0) {
updateUncapLevel(position, 6)
}
} }
} }