From 562b09b6e3ed1a2af0826478a9329c79664efe12 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Fri, 7 Jul 2023 06:20:40 +0300 Subject: [PATCH 1/9] Revert "fix: version download button dropdowns (#63)" This reverts commit e041c194a4a117ce569c7dae79626588504a3456. --- src/lib/components/mods/ModVersions.svelte | 80 ++++++++----------- .../[modId]/version/[versionId]/+page.svelte | 6 +- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/src/lib/components/mods/ModVersions.svelte b/src/lib/components/mods/ModVersions.svelte index 5f36a834d..e0cbb3ff9 100644 --- a/src/lib/components/mods/ModVersions.svelte +++ b/src/lib/components/mods/ModVersions.svelte @@ -6,9 +6,10 @@ import { base } from '$app/paths'; import Card, { Content } from '@smui/card'; import DataTable, { Head, Body, Row, Cell } from '@smui/data-table'; + import type { MenuComponentDev } from '@smui/menu'; import Menu from '@smui/menu'; import List, { Item } from '@smui/list'; - import Button, { Group, GroupItem, Label, Icon } from '@smui/button'; + import Button, { Label, Icon } from '@smui/button'; import { installMod } from '$lib/stores/launcher'; import { prettyDate, prettyNumber, prettyBytes, prettyArch } from '$lib/utils/formatting'; @@ -17,7 +18,7 @@ const client = getContextClient(); let expandedVersions = new Set(); - const menus = []; + let menu: MenuComponentDev; // TODO Pagination const versions = queryStore({ @@ -46,7 +47,7 @@ {:else if $versions.error} Oh no... {$versions.error.message} {:else} - + Version @@ -58,61 +59,46 @@ - {#each $versions.data.getMod.versions as version, i} + {#each $versions.data.getMod.versions as version} toggleRow(version.id)}> {version.version} {version.stability} {version.sml_version} {prettyNumber(version.downloads)} {prettyDate(version.created_at)} - -
{ - /*block table row expansion*/ - }}> - + +
{#if version.arch.length != 0} - - -
- - - - {#each version.arch as arch, _} - - - - {/each} - - -
-
+ + + + + + + {#each version.arch as arch, _} + + + + {/each} + + {:else} + {/if} - - + {#each $version.data.getVersion.arch as arch} From 3cf34d1f1a3a2fb2a7e06693f3dbc38b37ce0608 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Fri, 7 Jul 2023 06:32:41 +0300 Subject: [PATCH 2/9] Revert "SMR: Frontend support for Dedicated Servers (WIP) (#47)" This reverts commit 3b780f0d186f23fccd7d2cb22f2c4138b7f16ec0. --- .husky/commit-msg | 0 .husky/pre-commit | 0 package.json | 2 +- .../sml-versions/sml_version_admin.graphql | 5 -- .../sml-versions/sml_versions_admin.graphql | 5 -- .../admin/version/unapproved_versions.graphql | 6 +- src/gql/mods/mod.graphql | 24 ------- src/gql/mods/versions.graphql | 8 --- src/gql/sml/sml_versions.graphql | 5 -- src/gql/versions/mod_version.graphql | 8 --- src/lib/components/mods/ModVersions.svelte | 40 ++---------- .../sml-versions/SMLVersionForm.svelte | 65 ++++--------------- .../components/versions/VersionForm.svelte | 1 - src/lib/models/sml-versions.ts | 14 +--- src/lib/models/versions.ts | 27 +++----- src/lib/utils/formatting.ts | 13 ---- .../[smlVersionId]/edit/+page.svelte | 2 +- .../admin/sml-versions/new/+page.svelte | 2 +- .../[modId]/version/[versionId]/+page.svelte | 29 ++------- .../version/[versionId]/edit/+page.svelte | 1 - 20 files changed, 34 insertions(+), 223 deletions(-) mode change 100644 => 100755 .husky/commit-msg mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 77cad8d28..4af031c6f 100644 --- a/package.json +++ b/package.json @@ -173,4 +173,4 @@ "engines": { "node": ">= 18.0.0" } -} \ No newline at end of file +} diff --git a/src/gql/admin/sml-versions/sml_version_admin.graphql b/src/gql/admin/sml-versions/sml_version_admin.graphql index b4cb4f7f6..f27a8800f 100644 --- a/src/gql/admin/sml-versions/sml_version_admin.graphql +++ b/src/gql/admin/sml-versions/sml_version_admin.graphql @@ -4,11 +4,6 @@ query GetSMLVersionAdmin($smlVersionID: SMLVersionID!) { version stability link - arch { - id - platform - link - } changelog created_at date diff --git a/src/gql/admin/sml-versions/sml_versions_admin.graphql b/src/gql/admin/sml-versions/sml_versions_admin.graphql index bfccb34d4..98a318671 100644 --- a/src/gql/admin/sml-versions/sml_versions_admin.graphql +++ b/src/gql/admin/sml-versions/sml_versions_admin.graphql @@ -5,11 +5,6 @@ query GetSMLVersionsAdmin($filter: SMLVersionFilter) { version stability link - arch { - id - platform - link - } changelog created_at date diff --git a/src/gql/admin/version/unapproved_versions.graphql b/src/gql/admin/version/unapproved_versions.graphql index 09964cb94..530495004 100644 --- a/src/gql/admin/version/unapproved_versions.graphql +++ b/src/gql/admin/version/unapproved_versions.graphql @@ -6,13 +6,9 @@ query GetUnapprovedVersions($filter: VersionFilter) { version stability link - arch { - id - platform - asset - } changelog created_at + mod { name } diff --git a/src/gql/mods/mod.graphql b/src/gql/mods/mod.graphql index bae6d9fcb..351e583fe 100644 --- a/src/gql/mods/mod.graphql +++ b/src/gql/mods/mod.graphql @@ -13,14 +13,6 @@ query GetMod($mod: String!) { alpha { id link - arch { - id - ModVersionID - platform - asset - hash - size - } version created_at sml_version @@ -28,14 +20,6 @@ query GetMod($mod: String!) { beta { id link - arch { - id - ModVersionID - platform - asset - hash - size - } version created_at sml_version @@ -43,14 +27,6 @@ query GetMod($mod: String!) { release { id link - arch { - id - ModVersionID - platform - asset - hash - size - } version created_at sml_version diff --git a/src/gql/mods/versions.graphql b/src/gql/mods/versions.graphql index 4bf76d59c..831a97331 100644 --- a/src/gql/mods/versions.graphql +++ b/src/gql/mods/versions.graphql @@ -13,14 +13,6 @@ query GetModVersions($mod: ModID!, $limit: Int!, $offset: Int!) { link hash size - arch { - id - ModVersionID - platform - asset - hash - size - } } } } diff --git a/src/gql/sml/sml_versions.graphql b/src/gql/sml/sml_versions.graphql index 2d8636885..06ddfd911 100644 --- a/src/gql/sml/sml_versions.graphql +++ b/src/gql/sml/sml_versions.graphql @@ -7,11 +7,6 @@ query GetSMLVersions($limit: Int!, $offset: Int!) { stability changelog link - arch { - id - platform - link - } date satisfactory_version } diff --git a/src/gql/versions/mod_version.graphql b/src/gql/versions/mod_version.graphql index 3a73a754a..28bdd2bbe 100644 --- a/src/gql/versions/mod_version.graphql +++ b/src/gql/versions/mod_version.graphql @@ -10,14 +10,6 @@ query GetModVersion($version: VersionID!) { link hash size - arch { - id - ModVersionID - platform - asset - hash - size - } mod { id mod_reference diff --git a/src/lib/components/mods/ModVersions.svelte b/src/lib/components/mods/ModVersions.svelte index e0cbb3ff9..568b105a4 100644 --- a/src/lib/components/mods/ModVersions.svelte +++ b/src/lib/components/mods/ModVersions.svelte @@ -6,19 +6,15 @@ import { base } from '$app/paths'; import Card, { Content } from '@smui/card'; import DataTable, { Head, Body, Row, Cell } from '@smui/data-table'; - import type { MenuComponentDev } from '@smui/menu'; - import Menu from '@smui/menu'; - import List, { Item } from '@smui/list'; import Button, { Label, Icon } from '@smui/button'; import { installMod } from '$lib/stores/launcher'; - import { prettyDate, prettyNumber, prettyBytes, prettyArch } from '$lib/utils/formatting'; + import { prettyDate, prettyNumber, prettyBytes } from '$lib/utils/formatting'; export let modId!: string; const client = getContextClient(); let expandedVersions = new Set(); - let menu: MenuComponentDev; // TODO Pagination const versions = queryStore({ @@ -68,37 +64,9 @@ {prettyDate(version.created_at)}
- {#if version.arch.length != 0} - - - - - - - {#each version.arch as arch, _} - - - - {/each} - - - {:else} - - - {/if} + +
- {#if $data.bootstrap_version !== '0.0.0'} -
- - - {message || ''} - -
- {/if} +
+ + + {message || ''} + +
- - - - - - - - {message || ''} - - - {#if !editing} - - - {/if} -
- {/each} - - - + + {message || ''}
- - + + {message || ''}
diff --git a/src/lib/components/versions/VersionForm.svelte b/src/lib/components/versions/VersionForm.svelte index 14413dd85..697cee44e 100644 --- a/src/lib/components/versions/VersionForm.svelte +++ b/src/lib/components/versions/VersionForm.svelte @@ -16,7 +16,6 @@ export let modReference: string; export let onSubmit: (data: VersionData) => Promise; export let initialValues: Omit = { - arch: [{ ModVersionID: '', platform: '', asset: '', hash: '', size: 0 }], changelog: '', stability: VersionStabilities.Alpha }; diff --git a/src/lib/models/sml-versions.ts b/src/lib/models/sml-versions.ts index a1b397ef7..1d2589438 100644 --- a/src/lib/models/sml-versions.ts +++ b/src/lib/models/sml-versions.ts @@ -1,10 +1,5 @@ import * as zod from 'zod'; -import type { UpdateSmlArch, VersionStabilities } from '$lib/generated'; - -export type SMLArchData = { - platform: string; - link: string; -}; +import type { VersionStabilities } from '$lib/generated'; export type SMLVersionData = { version: string; @@ -14,24 +9,17 @@ export type SMLVersionData = { link: string; changelog: string; date: string; - arch: UpdateSmlArch[]; }; const versionRegex = /^(<=|<|>|>=|\^)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; -export const smlLinksSchema = zod.object({ - platform: zod.string(), - link: zod.string().url() -}); - export const smlVersionSchema = zod.object({ version: zod.string().regex(versionRegex), satisfactory_version: zod.number(), bootstrap_version: zod.string().regex(versionRegex), stability: zod.string(), link: zod.string().url(), - arch: zod.array(smlLinksSchema), changelog: zod.string(), date: zod.string() }); diff --git a/src/lib/models/versions.ts b/src/lib/models/versions.ts index 2e225c28e..1ff845be4 100644 --- a/src/lib/models/versions.ts +++ b/src/lib/models/versions.ts @@ -6,6 +6,12 @@ import type { ZodObject, ZodRawShape } from 'zod'; import type { File } from '$lib/models/file'; import type { VersionStabilities } from '$lib/generated'; +export type VersionData = { + file: File; + changelog: string; + stability: VersionStabilities; +}; + export type VersionMetadata = { uplugin: { Version: string; @@ -18,21 +24,6 @@ export type VersionMetadata = { objects: string[]; }; -export type modArchData = { - ModVersionID: string; - platform: string; - asset: string; - hash?: string; - size?: number; -}; - -export type VersionData = { - file: File; - changelog: string; - stability: VersionStabilities; - arch: modArchData[]; -}; - const validateUPluginJsonModZip = async ( zip: JSZip, uPluginJsonFile: JSZip.JSZipObject, @@ -68,7 +59,7 @@ const validateUPluginJsonModZip = async ( return { uplugin: parsed, - objects: Object.keys(zip.files).filter((f) => f.endsWith('.so') || f.endsWith('.dll') || f.endsWith('.pak')) + objects: Object.keys(zip.files).filter((f) => f.endsWith('.dll') || f.endsWith('.pak')) }; }) .catch((err) => ({ @@ -85,13 +76,13 @@ const validateModZip = async ( // eslint-disable-next-line @typescript-eslint/no-explicit-any .loadAsync(file as any) .then((zip) => { - const uPluginJsonFile = zip.file('WindowsNoEditor/' + modReference + '.uplugin'); + const uPluginJsonFile = zip.file(modReference + '.uplugin'); if (uPluginJsonFile) { return validateUPluginJsonModZip(zip, uPluginJsonFile, modReference); } return { - message: 'WindowsNoEditor/' + modReference + '.uplugin missing from mod' + message: modReference + '.uplugin missing from mod' }; }) .catch((err) => ({ diff --git a/src/lib/utils/formatting.ts b/src/lib/utils/formatting.ts index efffad6c1..13064927f 100644 --- a/src/lib/utils/formatting.ts +++ b/src/lib/utils/formatting.ts @@ -21,16 +21,3 @@ export const prettyBytes = (bytes: number, decimals = 2) => { return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; }; - -export const prettyArch = (platform: string) => { - switch (platform) { - case 'WindowsNoEditor': - return 'Windows Client'; - case 'WindowsServer': - return 'Windows Server'; - case 'LinuxServer': - return 'Linux Server'; - } - - return platform; -}; diff --git a/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte b/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte index 73274bf20..006599915 100644 --- a/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte +++ b/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte @@ -69,7 +69,7 @@ {:else if $smlVersion.error}

Oh no... {$smlVersion.error.message}

{:else} - + {/if} diff --git a/src/routes/admin/sml-versions/new/+page.svelte b/src/routes/admin/sml-versions/new/+page.svelte index 73298acce..e924b9c61 100644 --- a/src/routes/admin/sml-versions/new/+page.svelte +++ b/src/routes/admin/sml-versions/new/+page.svelte @@ -23,7 +23,7 @@ .then((value) => { if (value.error) { console.error(value.error.message); - errorMessage = 'Error creating SML Version: ' + value.error.message; + errorMessage = 'Error creating mod: ' + value.error.message; errorToast = true; } else { // TODO Toast or something diff --git a/src/routes/mod/[modId]/version/[versionId]/+page.svelte b/src/routes/mod/[modId]/version/[versionId]/+page.svelte index 24d27f7ae..88d8465e6 100644 --- a/src/routes/mod/[modId]/version/[versionId]/+page.svelte +++ b/src/routes/mod/[modId]/version/[versionId]/+page.svelte @@ -11,10 +11,7 @@ import { base } from '$app/paths'; import Button, { Label, Icon } from '@smui/button'; import Dialog, { Title, Content as DialogContent } from '@smui/dialog'; - import Menu from '@smui/menu'; - import List, { Item } from '@smui/list'; import { installMod } from '$lib/stores/launcher'; - import { prettyArch } from '$lib/utils/formatting'; import { getContextClient } from '@urql/svelte'; import type { PageData } from './$types'; @@ -26,7 +23,6 @@ let errorMessage = ''; let errorToast = false; - let menu: Menu; $: canUserEdit = $user?.roles?.deleteContent || @@ -78,27 +74,10 @@ {/if} - {#if $version.data.getVersion.arch.length != 0} - - - - {#each $version.data.getVersion.arch as arch} - - - - {/each} - - - {:else} - - - {/if} + +
@@ -61,6 +63,6 @@
- +
diff --git a/src/lib/components/mods/ModGrid.svelte b/src/lib/components/mods/ModGrid.svelte index b1bca0bca..a5c37fff6 100644 --- a/src/lib/components/mods/ModGrid.svelte +++ b/src/lib/components/mods/ModGrid.svelte @@ -41,7 +41,7 @@ variables: { offset: (page - 1) * perPage, limit: perPage, search, order, orderBy } }); - let totalMods: number; + let totalMods = 0; let searchField = search; @@ -73,7 +73,9 @@ goto(url.toString(), { keepFocus: true }); } - $: totalMods = $mods?.data?.getMods?.count || 0; + $: if ($mods?.data?.getMods?.count) { + totalMods = $mods.data.getMods.count; + } $: gridClasses = colCount == 4 @@ -126,7 +128,7 @@ {/if}
- +
@@ -148,7 +150,7 @@
- +
diff --git a/src/routes/admin/sml-versions/+page.svelte b/src/routes/admin/sml-versions/+page.svelte index 348bb30b7..c165d8fda 100644 --- a/src/routes/admin/sml-versions/+page.svelte +++ b/src/routes/admin/sml-versions/+page.svelte @@ -14,7 +14,7 @@ // TODO Selectable const perPage = 20; - const page = 1; + let page = 1; $: versions = queryStore({ query: GetSmlVersionsAdminDocument, @@ -27,7 +27,10 @@ } }); - $: totalVersions = $versions?.data?.getSMLVersions?.count; + let totalVersions = 0; + $: if ($versions?.data?.getSMLVersions?.count) { + totalVersions = $versions.data.getSMLVersions.count; + } const deleteVersion = (smlVersionID: string) => { client @@ -49,7 +52,7 @@ {#if totalVersions}
- +
{/if} @@ -95,7 +98,7 @@ {#if totalVersions}
- +
{/if} diff --git a/src/routes/admin/unapproved-mods/+page.svelte b/src/routes/admin/unapproved-mods/+page.svelte index c0098d9eb..27e524243 100644 --- a/src/routes/admin/unapproved-mods/+page.svelte +++ b/src/routes/admin/unapproved-mods/+page.svelte @@ -14,7 +14,7 @@ // TODO Selectable const perPage = 20; - const page = 1; + let page = 1; $: mods = queryStore({ query: GetUnapprovedModsDocument, @@ -27,7 +27,10 @@ } }); - $: totalMods = $mods?.data?.getUnapprovedMods?.count; + let totalMods = 0; + $: if ($mods?.data?.getUnapprovedMods?.count) { + totalMods = $mods.data.getUnapprovedMods.count; + } const approveMod = (modId: string) => { client @@ -57,7 +60,7 @@ {#if totalMods}
- +
{/if} @@ -100,7 +103,7 @@ {#if totalMods}
- +
{/if} diff --git a/src/routes/admin/unapproved-versions/+page.svelte b/src/routes/admin/unapproved-versions/+page.svelte index 4b0bacac6..1164405df 100644 --- a/src/routes/admin/unapproved-versions/+page.svelte +++ b/src/routes/admin/unapproved-versions/+page.svelte @@ -15,7 +15,7 @@ // TODO Selectable const perPage = 20; - const page = 1; + let page = 1; $: versions = queryStore({ query: GetUnapprovedVersionsDocument, @@ -28,7 +28,10 @@ } }); - $: totalVersions = $versions?.data?.getUnapprovedVersions?.count; + let totalVersions = 0; + $: if ($versions?.data?.getUnapprovedVersions?.count) { + totalVersions = $versions.data.getUnapprovedVersions.count; + } const approveVersion = (versionId: string) => { client @@ -58,7 +61,7 @@ {#if totalVersions}
- +
{/if} @@ -107,6 +110,6 @@ {#if totalVersions}
- +
{/if} diff --git a/src/routes/sml-versions/+page.svelte b/src/routes/sml-versions/+page.svelte index c8683ebed..62c024ecb 100644 --- a/src/routes/sml-versions/+page.svelte +++ b/src/routes/sml-versions/+page.svelte @@ -16,7 +16,7 @@ // TODO Selectable const perPage = 20; - const page = 1; + let page = 1; // TODO Pagination $: versions = queryStore({ @@ -28,7 +28,10 @@ } }); - $: totalVersions = $versions?.data?.getSMLVersions?.count; + let totalVersions = 0; + $: if ($versions?.data?.getSMLVersions?.count) { + totalVersions = $versions.data.getSMLVersions.count; + } const toggleRow = (versionId: string) => { if (expandedVersions.has(versionId)) { @@ -48,7 +51,7 @@ {#if totalVersions}
- +
{/if} @@ -101,7 +104,7 @@ {#if totalVersions}
- +
{/if} From d7718fabe4188be92e15f49fd9dbbd7f02c52cc0 Mon Sep 17 00:00:00 2001 From: mircearoata Date: Thu, 27 Jul 2023 11:54:29 +0300 Subject: [PATCH 7/9] fix: route params reactivity, graphql client token, mod grid navigation (#100) * fix: route params reactivity * fix: graphql client user token reactivity * chore: remove unnecessary getMe query store * fix: only update mod grid URL on search submit * fix: update page and search when navigating --- src/lib/components/auth/LoginDialog.svelte | 22 +++-------- src/lib/components/mods/ModGrid.svelte | 38 +++++++++++++++---- src/lib/core/graphql.ts | 29 +++++++------- src/routes/+page.svelte | 2 +- .../[smlVersionId]/edit/+page.svelte | 2 +- src/routes/guide/[guideId]/+page.svelte | 2 +- src/routes/guide/[guideId]/edit/+page.svelte | 2 +- src/routes/mod/[modId]/+page.svelte | 2 +- src/routes/mod/[modId]/edit/+page.svelte | 2 +- .../mod/[modId]/new-version/+page.svelte | 2 +- .../[modId]/version/[versionId]/+page.svelte | 2 +- .../version/[versionId]/edit/+page.svelte | 2 +- src/routes/user/[userId]/+page.svelte | 2 +- 13 files changed, 58 insertions(+), 51 deletions(-) diff --git a/src/lib/components/auth/LoginDialog.svelte b/src/lib/components/auth/LoginDialog.svelte index be0fee083..b216f4301 100644 --- a/src/lib/components/auth/LoginDialog.svelte +++ b/src/lib/components/auth/LoginDialog.svelte @@ -22,14 +22,6 @@ const client = getContextClient(); if (browser) { - const getMe = queryStore({ - query: GetMeDocument, - client, - variables: {}, - requestPolicy: 'network-only', - pause: true - }); - let first = true; userToken.subscribe((token) => { if (token) { @@ -53,21 +45,17 @@ first = false; if (token) { - getMe.pause(); - getMe.resume(); - - const unsub = getMe.subscribe((response) => { - if (!response.fetching) { + client + .query(GetMeDocument, {}, { requestPolicy: 'network-only' }) + .toPromise() + .then((response) => { if (response.error) { // TODO Toast or something console.error(response.error.message); - unsub(); } else if (response.data) { user.set(response.data.getMe); - unsub(); } - } - }); + }); } else { user.set(null); } diff --git a/src/lib/components/mods/ModGrid.svelte b/src/lib/components/mods/ModGrid.svelte index a5c37fff6..91cc2204a 100644 --- a/src/lib/components/mods/ModGrid.svelte +++ b/src/lib/components/mods/ModGrid.svelte @@ -10,7 +10,7 @@ import Fab from '@smui/fab'; import { Icon } from '@smui/common'; import { goto } from '$app/navigation'; - import { page as storePage } from '$app/stores'; + import { page as storePage, navigating } from '$app/stores'; import { user } from '$lib/stores/user'; import FicsitCard from '$lib/components/general/FicsitCard.svelte'; import Select, { Option } from '@smui/select'; @@ -66,13 +66,35 @@ }, 250) as unknown as number; } - $: if (browser) { - const url = new URL(window.location.origin + window.location.pathname); - url.searchParams.append('p', page.toString()); - searchField !== '' && searchField !== null && url.searchParams.append('q', searchField); - goto(url.toString(), { keepFocus: true }); + let urlSearch = searchField; + + $: if ($navigating && $navigating.type !== 'goto') { + searchField = $storePage.url.searchParams.get('q'); + page = parseInt($storePage.url.searchParams.get('p'), 10) || 1; + urlSearch = searchField; + } + + const updateUrl = () => { + if (browser && !$navigating) { + const url = new URL(window.location.origin + window.location.pathname); + url.searchParams.append('p', page.toString()); + urlSearch !== '' && urlSearch !== null && url.searchParams.append('q', urlSearch); + goto(url.toString(), { keepFocus: true }); + } + }; + + $: { + page; + urlSearch; + updateUrl(); } + const handleKeyDown = (event: CustomEvent | KeyboardEvent) => { + if ((event as KeyboardEvent).key === 'Enter') { + urlSearch = searchField; + } + }; + $: if ($mods?.data?.getMods?.count) { totalMods = $mods.data.getMods.count; } @@ -119,9 +141,9 @@ search - + - goto(base + '/mods?q=' + search)} color="primary" mini class="solo-fab" aria-label="Search"> + (urlSearch = searchField)} color="primary" mini class="solo-fab" aria-label="Search"> arrow_forward diff --git a/src/lib/core/graphql.ts b/src/lib/core/graphql.ts index 144dcd8e1..fcd1952e5 100644 --- a/src/lib/core/graphql.ts +++ b/src/lib/core/graphql.ts @@ -84,22 +84,19 @@ export const initializeGraphQLClient = (fetch?: LoadEvent['fetch']): Client => } } }), - authExchange(async (utils) => { - const token = get(userToken); - return { - addAuthToOperation(operation) { - return utils.appendHeaders(operation, { - Authorization: token - }); - }, - didAuthError(error) { - return error.message.indexOf('user not logged in') >= 0; - }, - async refreshAuth() { - // Token cannot be refreshed currently - } - }; - }), + authExchange(async (utils) => ({ + addAuthToOperation(operation) { + return utils.appendHeaders(operation, { + Authorization: get(userToken) + }); + }, + didAuthError(error) { + return error.message.indexOf('user not logged in') >= 0; + }, + async refreshAuth() { + // Token cannot be refreshed currently + } + })), persistedExchange({ preferGetForPersistedQueries: true }), diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ba6caf89a..7e2799d6f 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -12,7 +12,7 @@ export let data: PageData; - const { mods } = data; + $: ({ mods } = data); export const { t } = getTranslate(); diff --git a/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte b/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte index 006599915..464ea8f2f 100644 --- a/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte +++ b/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte @@ -12,7 +12,7 @@ export let data: PageData; - const { smlVersionId } = data; + $: ({ smlVersionId } = data); const client = getContextClient(); diff --git a/src/routes/guide/[guideId]/+page.svelte b/src/routes/guide/[guideId]/+page.svelte index 14fcc3590..db37fbb07 100644 --- a/src/routes/guide/[guideId]/+page.svelte +++ b/src/routes/guide/[guideId]/+page.svelte @@ -17,7 +17,7 @@ export let data: PageData; - const { guideId, guide } = data; + $: ({ guideId, guide } = data); const client = getContextClient(); diff --git a/src/routes/guide/[guideId]/edit/+page.svelte b/src/routes/guide/[guideId]/edit/+page.svelte index d0d0dc378..e177aec6a 100644 --- a/src/routes/guide/[guideId]/edit/+page.svelte +++ b/src/routes/guide/[guideId]/edit/+page.svelte @@ -12,7 +12,7 @@ export let data: PageData; - const { guideId } = data; + $: ({ guideId } = data); const client = getContextClient(); diff --git a/src/routes/mod/[modId]/+page.svelte b/src/routes/mod/[modId]/+page.svelte index 503df9b6d..3433e2ac1 100644 --- a/src/routes/mod/[modId]/+page.svelte +++ b/src/routes/mod/[modId]/+page.svelte @@ -21,7 +21,7 @@ export let data: PageData; - const { modId, mod } = data; + $: ({ modId, mod } = data); const client = getContextClient(); diff --git a/src/routes/mod/[modId]/edit/+page.svelte b/src/routes/mod/[modId]/edit/+page.svelte index bccb86d21..d06611236 100644 --- a/src/routes/mod/[modId]/edit/+page.svelte +++ b/src/routes/mod/[modId]/edit/+page.svelte @@ -13,7 +13,7 @@ export let data: PageData; - const { modId } = data; + $: ({ modId } = data); const client = getContextClient(); diff --git a/src/routes/mod/[modId]/new-version/+page.svelte b/src/routes/mod/[modId]/new-version/+page.svelte index 041b9220d..c3d809cd5 100644 --- a/src/routes/mod/[modId]/new-version/+page.svelte +++ b/src/routes/mod/[modId]/new-version/+page.svelte @@ -15,7 +15,7 @@ export let data: PageData; - const { modId } = data; + $: ({ modId } = data); const client = getContextClient(); diff --git a/src/routes/mod/[modId]/version/[versionId]/+page.svelte b/src/routes/mod/[modId]/version/[versionId]/+page.svelte index 88d8465e6..b0ba88cfe 100644 --- a/src/routes/mod/[modId]/version/[versionId]/+page.svelte +++ b/src/routes/mod/[modId]/version/[versionId]/+page.svelte @@ -17,7 +17,7 @@ export let data: PageData; - const { modId, versionId, version } = data; + $: ({ modId, versionId, version } = data); const client = getContextClient(); diff --git a/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte b/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte index cc3c30bfb..c576e6763 100644 --- a/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte +++ b/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte @@ -12,7 +12,7 @@ export let data: PageData; - const { modId, versionId } = data; + $: ({ modId, versionId } = data); const client = getContextClient(); diff --git a/src/routes/user/[userId]/+page.svelte b/src/routes/user/[userId]/+page.svelte index 37cdf47e3..bb8995164 100644 --- a/src/routes/user/[userId]/+page.svelte +++ b/src/routes/user/[userId]/+page.svelte @@ -11,7 +11,7 @@ export let data: PageData; - const { user } = data; + $: ({ user } = data); let guidesTab = false; From 48d62f7cfac9e0437a31f27edaec00a723967786 Mon Sep 17 00:00:00 2001 From: mircearoata Date: Fri, 28 Jul 2023 13:00:57 +0300 Subject: [PATCH 8/9] fix: user page getting incomplete mod data (#102) --- src/gql/users/user.graphql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gql/users/user.graphql b/src/gql/users/user.graphql index c201e65b9..6493d2ef6 100644 --- a/src/gql/users/user.graphql +++ b/src/gql/users/user.graphql @@ -40,6 +40,10 @@ query GetUser($user: UserID!) { note } } + tags { + id + name + } } } guides { From 8d1081ca7b4d5afc2b748eed10cd54d947602d3e Mon Sep 17 00:00:00 2001 From: mircearoata Date: Sat, 29 Jul 2023 01:50:50 +0300 Subject: [PATCH 9/9] fix: make queryStores reactive to get valid variables (#103) * fix: make queryStores reactive to get valid variables * chore: readme info about testing local sign in --------- Co-authored-by: Rob B --- README.md | 8 ++++++++ cspell.json | 2 +- src/lib/components/mods/ModVersions.svelte | 2 +- .../admin/sml-versions/[smlVersionId]/edit/+page.svelte | 2 +- src/routes/guide/[guideId]/edit/+page.svelte | 2 +- src/routes/mod/[modId]/edit/+page.svelte | 5 ++--- src/routes/mod/[modId]/new-version/+page.svelte | 2 +- .../mod/[modId]/version/[versionId]/edit/+page.svelte | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index abf0d601e..bbf2dc409 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,11 @@ and will start a development server on port 3000. If you don't wish to run the backend locally (which most likely you don't), you can point your local frontend to the staging or production APIs by specifying a different `NODE_ENV`, such as `staging`. + +### Login + +Trying to log in on a locally hosted copy of the frontend will fail and redirect you to the live site +because of how the OAuth sign in process works. +To work around this, copy the `token` cookie produced by signing into the real site (`.ficsit.app`) +and add it to your cookies for `localhost`. +There is likely a cookie manager extension for your browser of choice that will make this easier. diff --git a/cspell.json b/cspell.json index 5f9d71d3e..c983299b4 100644 --- a/cspell.json +++ b/cspell.json @@ -5,7 +5,7 @@ // language - current active spelling language "language": "en", // words - list of words to be always considered correct - "words": ["cfworker", "felte", "prismjs", "smui", "urql", "wonka"], + "words": ["cfworker", "felte", "ficsit", "prismjs", "smui", "urql", "wonka"], // flagWords - list of words to be always considered incorrect // This is useful for offensive words and common spelling errors. // cSpell:disable (don't complain about the words we listed here) diff --git a/src/lib/components/mods/ModVersions.svelte b/src/lib/components/mods/ModVersions.svelte index 568b105a4..ca4ebc7b2 100644 --- a/src/lib/components/mods/ModVersions.svelte +++ b/src/lib/components/mods/ModVersions.svelte @@ -17,7 +17,7 @@ let expandedVersions = new Set(); // TODO Pagination - const versions = queryStore({ + $: versions = queryStore({ query: GetModVersionsDocument, client, variables: { diff --git a/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte b/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte index 464ea8f2f..a06e58f95 100644 --- a/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte +++ b/src/routes/admin/sml-versions/[smlVersionId]/edit/+page.svelte @@ -19,7 +19,7 @@ let errorMessage = ''; let errorToast = false; - const smlVersion = queryStore({ + $: smlVersion = queryStore({ query: GetSmlVersionAdminDocument, client, variables: { smlVersionID: smlVersionId } diff --git a/src/routes/guide/[guideId]/edit/+page.svelte b/src/routes/guide/[guideId]/edit/+page.svelte index e177aec6a..13e97f2b3 100644 --- a/src/routes/guide/[guideId]/edit/+page.svelte +++ b/src/routes/guide/[guideId]/edit/+page.svelte @@ -19,7 +19,7 @@ let errorMessage = ''; let errorToast = false; - const guide = queryStore({ + $: guide = queryStore({ query: GetGuideDocument, client, variables: { guide: guideId } diff --git a/src/routes/mod/[modId]/edit/+page.svelte b/src/routes/mod/[modId]/edit/+page.svelte index d06611236..2a8390c45 100644 --- a/src/routes/mod/[modId]/edit/+page.svelte +++ b/src/routes/mod/[modId]/edit/+page.svelte @@ -8,7 +8,6 @@ import { base } from '$app/paths'; import MetaDescriptors from '$lib/components/utils/MetaDescriptors.svelte'; import Card, { Content } from '@smui/card'; - import { get } from 'svelte/store'; import type { PageData } from './$types'; export let data: PageData; @@ -20,7 +19,7 @@ let errorMessage = ''; let errorToast = false; - const mod = queryStore({ + $: mod = queryStore({ query: GetModDocument, client, variables: { mod: modId } @@ -29,7 +28,7 @@ const onSubmit = (modData: ModData) => { client .mutation(EditModDocument, { - modId: get(mod).data.mod.id, + modId: $mod.data.mod.id, mod: modData }) .toPromise() diff --git a/src/routes/mod/[modId]/new-version/+page.svelte b/src/routes/mod/[modId]/new-version/+page.svelte index c3d809cd5..f747d01fe 100644 --- a/src/routes/mod/[modId]/new-version/+page.svelte +++ b/src/routes/mod/[modId]/new-version/+page.svelte @@ -39,7 +39,7 @@ let errorMessage = ''; let errorToast = false; - const mod = queryStore({ + $: mod = queryStore({ query: GetModReferenceDocument, client, variables: { mod: modId } diff --git a/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte b/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte index c576e6763..56caecb98 100644 --- a/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte +++ b/src/routes/mod/[modId]/version/[versionId]/edit/+page.svelte @@ -19,7 +19,7 @@ let errorMessage = ''; let errorToast = false; - const version = queryStore({ + $: version = queryStore({ query: GetModVersionDocument, client, variables: { version: versionId }