From 8e18262db094636bd02be27c5d94f34155703bef Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 4 May 2021 13:43:32 -0700 Subject: [PATCH] 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! --- src/app/WardrobePage/useOutfitSaving.js | 14 +++++++------- src/server/types/Outfit.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/WardrobePage/useOutfitSaving.js b/src/app/WardrobePage/useOutfitSaving.js index e0c754e..e182857 100644 --- a/src/app/WardrobePage/useOutfitSaving.js +++ b/src/app/WardrobePage/useOutfitSaving.js @@ -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, }); } }, diff --git a/src/server/types/Outfit.js b/src/server/types/Outfit.js index c3c4bc1..42287c9 100644 --- a/src/server/types/Outfit.js +++ b/src/server/types/Outfit.js @@ -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})`; }