Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: editing mod tags and authors #187

Merged
merged 3 commits into from
Sep 29, 2024

Conversation

knightzac19
Copy link
Contributor

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

Copy link

vercel bot commented Sep 23, 2024

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

A member of the Team first needs to authorize it.

@knightzac19 knightzac19 marked this pull request as draft September 23, 2024 18:36
Copy link

vercel bot commented Sep 23, 2024

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 knightzac19 marked this pull request as ready for review September 23, 2024 19:25
budak7273
budak7273 previously approved these changes Sep 27, 2024
Copy link
Member

@budak7273 budak7273 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and it fixes #162 for me

Copy link
Member

@mircearoata mircearoata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

src/lib/components/utils/TagList.svelte Outdated Show resolved Hide resolved
src/lib/components/utils/TagList.svelte Outdated Show resolved Hide resolved
src/lib/components/utils/TagList.svelte Outdated Show resolved Hide resolved
src/routes/mod/[modId]/+page.svelte Outdated Show resolved Hide resolved
src/lib/components/mods/ModForm.svelte Outdated Show resolved Hide resolved
@knightzac19
Copy link
Contributor Author

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.

@budak7273 budak7273 changed the title feat: fix editing mods, specifically tags fix: editing mod tags and authors Sep 29, 2024
@mircearoata
Copy link
Member

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)

@budak7273 budak7273 merged commit 028d2a2 into satisfactorymodding:staging Sep 29, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Status: 🚢 Released
Development

Successfully merging this pull request may close these issues.

Adding an author to a mod with tags fails and makes the tags list uneditable until the page is refreshed
3 participants