Fix making changes while outfit is saving
Before this, if you made a change while the outfit was auto-saving, it would reset your changes back and forth in an infinite loop, oops! This was because the response from the save would reset the outfit state to match, but the _debounced_ outfit state would still show the user's changes, so we'd trigger another save. And then the same thing would happen in reverse, and back and forth again!
This commit is contained in:
parent
3088b97ad2
commit
8e18262db0
2 changed files with 8 additions and 8 deletions
|
@ -113,15 +113,15 @@ function useOutfitSaving(outfitState, dispatchToOutfit) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Also, send a `reset` action, to show whatever the server returned.
|
// Also, send a `rename` action, if this is still the current outfit,
|
||||||
// This is important for suffix changes to `name`, but can also be
|
// and the server renamed it (e.g. "Untitled outfit (1)"). (It's
|
||||||
// relevant for graceful failure when a bug causes a change not to
|
// tempting to do a full reset, in case the server knows something we
|
||||||
// persist. (But don't do it if it's not the current outfit anymore,
|
// don't, but we don't want to clobber changes the user made since
|
||||||
// we don't want laggy mutations to reset the outfit!)
|
// starting the save!)
|
||||||
if (outfit.id === outfitState.id) {
|
if (outfit.id === outfitState.id) {
|
||||||
dispatchToOutfit({
|
dispatchToOutfit({
|
||||||
type: "resetToSavedOutfitData",
|
type: "rename",
|
||||||
savedOutfitData: outfit,
|
outfitName: outfit.name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -165,7 +165,7 @@ const resolvers = {
|
||||||
// Then, get the unique name to use for this outfit: try the provided
|
// Then, get the unique name to use for this outfit: try the provided
|
||||||
// name first, but, if it's taken, add a "(1)" suffix and keep
|
// name first, but, if it's taken, add a "(1)" suffix and keep
|
||||||
// incrementing it until it's not.
|
// incrementing it until it's not.
|
||||||
let name = rawName;
|
let name = rawName || "Untitled outfit";
|
||||||
for (let i = 1; existingOutfitNames.has(name); i++) {
|
for (let i = 1; existingOutfitNames.has(name); i++) {
|
||||||
name = `${baseName} (${i})`;
|
name = `${baseName} (${i})`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue