From f39fb126664b24d4916bdc3b90bbb6799f433608 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Sat, 6 Jan 2024 09:53:28 +0200 Subject: [PATCH] feat: tag descriptions --- src/gql/home/mods.graphql | 1 + src/gql/home/tags.graphql | 1 + src/gql/mods/edit_mod.graphql | 1 + src/gql/mods/mod.graphql | 1 + src/gql/tags/create_tag.graphql | 5 +-- src/gql/tags/update_tag.graphql | 5 +-- src/lib/components/utils/TagList.svelte | 3 +- src/routes/admin/tag-manager/+page.svelte | 38 ++++++++++++++++------- 8 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/gql/home/mods.graphql b/src/gql/home/mods.graphql index de8283b5b..b20d9582f 100644 --- a/src/gql/home/mods.graphql +++ b/src/gql/home/mods.graphql @@ -41,6 +41,7 @@ query GetMods($offset: Int!, $limit: Int!, $search: String, $order: Order, $orde tags { id name + description } } } diff --git a/src/gql/home/tags.graphql b/src/gql/home/tags.graphql index b17598f4c..b62e223d6 100644 --- a/src/gql/home/tags.graphql +++ b/src/gql/home/tags.graphql @@ -2,5 +2,6 @@ query GetTags($limit: Int) { getTags(filter: { limit: $limit }) { id name + description } } diff --git a/src/gql/mods/edit_mod.graphql b/src/gql/mods/edit_mod.graphql index 21e92652c..5217ea430 100644 --- a/src/gql/mods/edit_mod.graphql +++ b/src/gql/mods/edit_mod.graphql @@ -28,6 +28,7 @@ mutation EditMod($modId: ModID!, $mod: UpdateMod!) { tags { id name + description } } } diff --git a/src/gql/mods/mod.graphql b/src/gql/mods/mod.graphql index 83833fc8c..37b192898 100644 --- a/src/gql/mods/mod.graphql +++ b/src/gql/mods/mod.graphql @@ -86,6 +86,7 @@ query GetMod($mod: String!) { tags { id name + description } } } diff --git a/src/gql/tags/create_tag.graphql b/src/gql/tags/create_tag.graphql index e3ff81f85..48852f3cc 100644 --- a/src/gql/tags/create_tag.graphql +++ b/src/gql/tags/create_tag.graphql @@ -1,6 +1,7 @@ -mutation CreateTag($tagName: TagName!) { - createTag(tagName: $tagName) { +mutation CreateTag($tagName: TagName!, $description: String!) { + createTag(tagName: $tagName, description: $description) { id name + description } } diff --git a/src/gql/tags/update_tag.graphql b/src/gql/tags/update_tag.graphql index 4f94f0f67..2b26bc8f9 100644 --- a/src/gql/tags/update_tag.graphql +++ b/src/gql/tags/update_tag.graphql @@ -1,6 +1,7 @@ -mutation UpdateTag($tagID: TagID!, $tagName: TagName!) { - updateTag(tagID: $tagID, NewName: $tagName) { +mutation UpdateTag($tagID: TagID!, $tagName: TagName!, $description: String!) { + updateTag(tagID: $tagID, NewName: $tagName, description: $description) { id name + description } } diff --git a/src/lib/components/utils/TagList.svelte b/src/lib/components/utils/TagList.svelte index a094988f0..3b2a0692a 100644 --- a/src/lib/components/utils/TagList.svelte +++ b/src/lib/components/utils/TagList.svelte @@ -40,7 +40,8 @@ ...tags, { id: tag.value, - name: tag.label + name: tag.label, + description: $getAllTags.data?.getTags?.find((t) => t.id == tag.value).description } ]; diff --git a/src/routes/admin/tag-manager/+page.svelte b/src/routes/admin/tag-manager/+page.svelte index 718502b89..394935974 100644 --- a/src/routes/admin/tag-manager/+page.svelte +++ b/src/routes/admin/tag-manager/+page.svelte @@ -25,7 +25,7 @@ function newTag() { if (!tags.find((tag) => tag.name == 'New Tag')) { - const tag = { id: tagNegativeID--, name: 'New Tag' } as Tag; + const tag = { id: tagNegativeID--, name: 'New Tag', description: 'Description' } as Tag; tags.push(tag); tags = tags; setTimeout(() => { @@ -51,7 +51,9 @@ if (tag.id < 0) { // Create new tag & update tag.id with new DB id or re-fetch all tags try { - const result = await client.mutation(CreateTagDocument, { tagName: tag.name }).toPromise(); + const result = await client + .mutation(CreateTagDocument, { tagName: tag.name, description: tag.description }) + .toPromise(); if (result.data) { tag.id = result.data.createTag.id; success = true; @@ -71,8 +73,11 @@ // Update existing tag try { success = - (await client.mutation(UpdateTagDocument, { tagID: tag.id, tagName: tag.name }).toPromise()).data.updateTag != - null; + ( + await client + .mutation(UpdateTagDocument, { tagID: tag.id, tagName: tag.name, description: tag.description }) + .toPromise() + ).data.updateTag != null; } catch { // nothing } @@ -137,14 +142,23 @@ {tag.name} - tagChange(tag)} /> - Human-Readable name of the tag that is shown in UI +
+ tagChange(tag)} /> + + tagChange(tag)} /> +
+ Human-Readable name and description of the tag that is shown in UI