Oops, don't allow saving existing outfits

Ah, oops, the `id` field from `useOutfitState` went missing and I didn't notice, so `useOutfitSaving` didn't correctly detect that this was an existing outfit!

This made saves on existing outfits create new copies, which isn't a bad behavior exactly, but I don't want to go there; saving a copy is just gonna pollute people's outfit lists rn, worse than no option imo.
This commit is contained in:
Emi Matchu 2021-04-20 01:50:42 -07:00
parent 3f66dd7244
commit 5ac758cc72
2 changed files with 5 additions and 3 deletions

View file

@ -255,13 +255,15 @@ function useOutfitSaving(outfitState) {
const history = useHistory(); const history = useHistory();
const toast = useToast(); const toast = useToast();
const isSaved = outfitState.id; const isSaved = Boolean(outfitState.id);
// Only logged-in users can save outfits - and they can only save new outfits, // Only logged-in users can save outfits - and they can only save new outfits,
// or outfits they created. // or outfits they created.
const canSaveOutfit = const canSaveOutfit =
isLoggedIn && isLoggedIn &&
(!isSaved || outfitState.creator?.id === currentUserId) && (!isSaved || outfitState.creator?.id === currentUserId) &&
// TODO: Add support for updating outfits
!isSaved &&
// TODO: Add support for outfits with items // TODO: Add support for outfits with items
outfitState.wornItemIds.length === 0 && outfitState.wornItemIds.length === 0 &&
outfitState.closetedItemIds.length === 0; outfitState.closetedItemIds.length === 0;

View file

@ -107,7 +107,7 @@ function useOutfitState() {
// IDs. It's more convenient to manage them as a Set in state, but most // IDs. It's more convenient to manage them as a Set in state, but most
// callers will find it more convenient to access them as arrays! e.g. for // callers will find it more convenient to access them as arrays! e.g. for
// `.map()`. // `.map()`.
const { name, speciesId, colorId, pose, appearanceId } = outfitState; const { id, name, speciesId, colorId, pose, appearanceId } = outfitState;
const wornItemIds = Array.from(outfitState.wornItemIds); const wornItemIds = Array.from(outfitState.wornItemIds);
const closetedItemIds = Array.from(outfitState.closetedItemIds); const closetedItemIds = Array.from(outfitState.closetedItemIds);
const allItemIds = [...wornItemIds, ...closetedItemIds]; const allItemIds = [...wornItemIds, ...closetedItemIds];
@ -218,7 +218,7 @@ function useOutfitState() {
const url = buildOutfitUrl(outfitState); const url = buildOutfitUrl(outfitState);
const outfitStateWithExtras = { const outfitStateWithExtras = {
id: urlOutfitState.outfitId, id,
creator, creator,
zonesAndItems, zonesAndItems,
incompatibleItems, incompatibleItems,