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:
Emi Matchu 2021-05-04 13:43:32 -07:00
parent 3088b97ad2
commit 8e18262db0
2 changed files with 8 additions and 8 deletions

View file

@ -113,15 +113,15 @@ function useOutfitSaving(outfitState, dispatchToOutfit) {
},
});
// Also, send a `reset` action, to show whatever the server returned.
// This is important for suffix changes to `name`, but can also be
// relevant for graceful failure when a bug causes a change not to
// persist. (But don't do it if it's not the current outfit anymore,
// we don't want laggy mutations to reset the outfit!)
// Also, send a `rename` action, if this is still the current outfit,
// and the server renamed it (e.g. "Untitled outfit (1)"). (It's
// tempting to do a full reset, in case the server knows something we
// don't, but we don't want to clobber changes the user made since
// starting the save!)
if (outfit.id === outfitState.id) {
dispatchToOutfit({
type: "resetToSavedOutfitData",
savedOutfitData: outfit,
type: "rename",
outfitName: outfit.name,
});
}
},

View file

@ -165,7 +165,7 @@ const resolvers = {
// 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
// incrementing it until it's not.
let name = rawName;
let name = rawName || "Untitled outfit";
for (let i = 1; existingOutfitNames.has(name); i++) {
name = `${baseName} (${i})`;
}