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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/lib/components/mods/ModForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@
onSubmit: (submitted: ModData) => onSubmit(trimNonSchema(submitted, modSchema))
});

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

$: if (tags) {
computeTags();
}

// The GQL type NewMod does not have a compatibility field.
Expand Down
4 changes: 1 addition & 3 deletions src/lib/components/utils/TagList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
target: 'popupAutocomplete',
placement: 'bottom-start'
};

let tagList = [];
const loadTagList = () => (tagList = tags.map((t: Tag) => t.name));

Expand All @@ -55,7 +54,6 @@
const removeTag = (label: string) => {
const idx = tags.findIndex((t) => t.name === label);
tags = [...tags.slice(0, idx), ...tags.slice(idx + 1)];

loadTagList();
};

Expand All @@ -64,7 +62,7 @@

<div class="tags">
{#if !editable}
{#if tags.length > 0}
{#if tags && tags.length > 0}
<div class="text-md flex flex-row flex-wrap gap-1">
{#each tags as tag}
<TagDisplay {tag} {popupTriggerEvent} />
Expand Down
3 changes: 2 additions & 1 deletion src/routes/mod/[modId]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const load: PageLoad = async ({ params, parent }) => ({
mod: queryStore({
query: GetModDocument,
client: (await parent()).client,
variables: { mod: params.modId }
variables: { mod: params.modId },
requestPolicy: 'network-only'
})
}))
});
17 changes: 5 additions & 12 deletions src/routes/mod/[modId]/edit/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
<script lang="ts">
import { getContextClient, queryStore } from '@urql/svelte';
import { EditModDocument, GetModDocument } from '$lib/generated';
import { getContextClient } from '@urql/svelte';
import { EditModDocument } from '$lib/generated';
import { goto } from '$app/navigation';
import ModForm from '$lib/components/mods/ModForm.svelte';
import type { ModData } from '$lib/models/mods';
import { base } from '$app/paths';
import MetaDescriptors from '$lib/components/utils/MetaDescriptors.svelte';
import { get } from 'svelte/store';
import type { PageData } from './$types';
import { getToastStore } from '@skeletonlabs/skeleton';
import { get } from 'svelte/store';

export let data: PageData;

const { modId } = data;

const client = getContextClient();

const toastStore = getToastStore();

const mod = queryStore({
query: GetModDocument,
client,
variables: { mod: modId }
});
$: ({ modId, mod } = data);

const onSubmit = (modData: ModData) => {
client
Expand All @@ -45,7 +38,7 @@
background: 'variant-filled-success',
timeout: 5000
});
goto(base + '/mod/' + value.data.updateMod.id);
goto(base + '/mod/' + modId);
}
});
};
Expand Down
15 changes: 13 additions & 2 deletions src/routes/mod/[modId]/edit/+page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { GetModDocument } from '$lib/generated';
import { loadWaitForNoFetch } from '$lib/utils/gql';
import { queryStore } from '@urql/svelte';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ params }) => ({
...params
export const load: PageLoad = async ({ params, parent }) => ({
...params,
...(await loadWaitForNoFetch({
mod: queryStore({
query: GetModDocument,
client: (await parent()).client,
variables: { mod: params.modId },
requestPolicy: 'network-only'
})
}))
});