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...
This commit is contained in:
Emi Matchu 2021-01-17 07:43:08 -08:00
parent f1dd3bffa6
commit 2dbed8b8c4

View file

@ -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[]")),