Skip to content

Commit

Permalink
feat: tag descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jan 6, 2024
1 parent f0fce56 commit f39fb12
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/gql/home/mods.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ query GetMods($offset: Int!, $limit: Int!, $search: String, $order: Order, $orde
tags {
id
name
description
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/gql/home/tags.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ query GetTags($limit: Int) {
getTags(filter: { limit: $limit }) {
id
name
description
}
}
1 change: 1 addition & 0 deletions src/gql/mods/edit_mod.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mutation EditMod($modId: ModID!, $mod: UpdateMod!) {
tags {
id
name
description
}
}
}
1 change: 1 addition & 0 deletions src/gql/mods/mod.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ query GetMod($mod: String!) {
tags {
id
name
description
}
}
}
5 changes: 3 additions & 2 deletions src/gql/tags/create_tag.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
5 changes: 3 additions & 2 deletions src/gql/tags/update_tag.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 2 additions & 1 deletion src/lib/components/utils/TagList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
];
Expand Down
38 changes: 26 additions & 12 deletions src/routes/admin/tag-manager/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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;
Expand All @@ -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
}
Expand Down Expand Up @@ -137,14 +142,23 @@
<AccordionItem>
<svelte:fragment slot="summary">{tag.name}</svelte:fragment>
<svelte:fragment slot="content">
<input
type="text"
class="input p-2"
bind:value={tag.name}
placeholder="Tag-Name"
bind:this={nameFields[tag.id]}
on:change={() => tagChange(tag)} />
<span slot="helper">Human-Readable name of the tag that is shown in UI</span>
<div>
<input
type="text"
class="input p-2"
bind:value={tag.name}
placeholder="Name"
bind:this={nameFields[tag.id]}
on:change={() => tagChange(tag)} />

<input
type="text"
class="input p-2"
bind:value={tag.description}
placeholder="Description"
on:change={() => tagChange(tag)} />
</div>
<span slot="helper">Human-Readable name and description of the tag that is shown in UI</span>

<button class="variant-ghost-error btn" on:click={(e) => onDeleteClick(e, tag)}>
<span>Delete</span>
Expand Down

0 comments on commit f39fb12

Please sign in to comment.