From 2dbed8b8c48a8d7f4b1fe565da6427872352abd9 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 17 Jan 2021 07:43:08 -0800 Subject: [PATCH] Use default values for plain /outfits/new URLs Previously, if you navigated to /outfits/new without a species or color in the query string, we'd show a blank outfit page, with the species/color picker hidden. Now, we default to a Blue Acara instead! We don't do anything to handle _invalid_ species/color IDs, but I don't super mind that, because in practice that would require some call site to malform the URL, and I don't super expect that. This resolves more of the _cause_ of Sentry issue IMPRESS-2020-8, but I'm still wondering how a user got to the URL `/outfits/new?[object+Object]=&objects[]=35185&objects[]=67084`. I'm wondering if the pet loader on the homepage has a bug in Safari? I feel like I heard something like that from the feedback form, too... --- src/app/WardrobePage/useOutfitState.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/app/WardrobePage/useOutfitState.js b/src/app/WardrobePage/useOutfitState.js index 5a03cbc..7e9c411 100644 --- a/src/app/WardrobePage/useOutfitState.js +++ b/src/app/WardrobePage/useOutfitState.js @@ -340,13 +340,30 @@ const outfitStateReducer = (apolloClient) => (baseState, action) => { function useParseOutfitUrl() { const { id } = useParams(); - const urlParams = new URLSearchParams(window.location.search); + // For the /outfits/:id page, ignore the query string, and just wait for the + // outfit data to load in! + if (id != null) { + return { + id, + name: null, + speciesId: null, + colorId: null, + pose: null, + appearanceId: null, + wornItemIds: [], + closetedItemIds: [], + }; + } + + // Otherwise, parse the query string, and fill in default values for anything + // not specified. + const urlParams = new URLSearchParams(window.location.search); return { id: id, name: urlParams.get("name"), - speciesId: urlParams.get("species"), - colorId: urlParams.get("color"), + speciesId: urlParams.get("species") || "1", + colorId: urlParams.get("color") || "8", pose: urlParams.get("pose") || "HAPPY_FEM", appearanceId: urlParams.get("state") || null, wornItemIds: new Set(urlParams.getAll("objects[]")),