satisfactorymodding / smr-frontend

Next generation Satisfactory Modding Repository (SMR) frontend
https://satisfactorymodding.github.io/smr-frontend/main/
GNU General Public License v3.0
6 stars 24 forks source link

fix: editing mod tags and authors #187

Closed knightzac19 closed 2 months ago

knightzac19 commented 2 months ago

This should resolve #162 and any wonkiness that editing a mod was having due to stale data.

vercel[bot] commented 2 months ago

@knightzac19 is attempting to deploy a commit to the satisfactorymodding Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
smr-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 23, 2024 6:39pm
knightzac19 commented 2 months ago

Most of this is unnecessary, the issue is that the TagsList uses InputChip with name="tags" which means that on input updates the form data will be updated with the tag chip text, but the tagIDs field is updated from $data.tags instead of tags, so it reads the id field of strings, and ends up being full of undefined, failing the validation.

The only thing needed to fix the issue is

diff --git a/src/lib/components/mods/ModForm.svelte b/src/lib/components/mods/ModForm.svelte
index a62f7e0..8bd9982 100644
--- a/src/lib/components/mods/ModForm.svelte
+++ b/src/lib/components/mods/ModForm.svelte
@@ -45,15 +45,9 @@
     onSubmit: (submitted: ModData) => onSubmit(trimNonSchema(submitted, modSchema))
   });

-  let tags = [];
-  $: {
-    const anyData = $data;
-    if (anyData.tags) {
-      tags = anyData.tags;
-      delete anyData.tags;
-    }
-    $data.tagIDs = tags.map((tag) => tag.id);
-  }
+  let tags = $data.tags ?? [];
+
+  $: $data.tagIDs = tags.map((tag) => tag.id);

   // The GQL type NewMod does not have a compatibility field.
   // We remove the field from the data so that the GQL request is valid

I also left a few pointers about svelte as comments on the code

Alright, I cleaned up most of the code, I was running into a lot of strange non-updating issues and undefined issues which led me down a rabbit hole. So getting rid of a lot of the extra code still let things work properly.

mircearoata commented 2 months ago

I guess you're referring to the redirect back to the mod page after editing twice being blank. That one is really odd, because the API returns null for the tags on the UpdateMod mutation, but not for the authors, which are also a relation, and I don't see how this could even be happening, but refetching the data does work around this issue, and it shouldn't cause that many extra queries (unless someone is constantly navigating between the mods list and a mod page)