diff --git a/src/routes/(app)/(library)/+page.ts b/src/routes/(app)/(library)/+page.ts new file mode 100644 index 0000000..3773e33 --- /dev/null +++ b/src/routes/(app)/(library)/+page.ts @@ -0,0 +1,25 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +import { browser } from '$app/environment'; +import { getCategories, getCategory } from '$lib/gql/Queries'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = ({ fetch, url }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getCategories, + {}, + { + fetch + } + ); + const tab = parseInt(url.searchParams.get('tab') ?? '0'); + mod.client.query(getCategory, { id: tab }, { fetch }); + })(); +}; diff --git a/src/routes/(app)/browse/extensions/+page.ts b/src/routes/(app)/browse/extensions/+page.ts new file mode 100644 index 0000000..9f54d82 --- /dev/null +++ b/src/routes/(app)/browse/extensions/+page.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +import { browser } from '$app/environment'; +import { getExtensions } from '$lib/gql/Queries'; +import { gmState } from '$lib/simpleStores.svelte'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = ({ fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getExtensions, + { isNsfw: gmState.value.nsfw ? null : false }, + { + fetch + } + ); + })(); +}; diff --git a/src/routes/(app)/browse/globalsearch/+page.ts b/src/routes/(app)/browse/globalsearch/+page.ts new file mode 100644 index 0000000..a59c3cb --- /dev/null +++ b/src/routes/(app)/browse/globalsearch/+page.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +import { browser } from '$app/environment'; +import { getSources } from '$lib/gql/Queries'; +import { gmState } from '$lib/simpleStores.svelte'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = ({ fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getSources, + { isNsfw: gmState.value.nsfw ? null : false }, + { + fetch + } + ); + })(); +}; diff --git a/src/routes/(app)/browse/migrate/+page.ts b/src/routes/(app)/browse/migrate/+page.ts new file mode 100644 index 0000000..32da864 --- /dev/null +++ b/src/routes/(app)/browse/migrate/+page.ts @@ -0,0 +1,23 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import { browser } from '$app/environment'; +import { sourcesMigration } from '$lib/gql/Queries'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = ({ params, fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + sourcesMigration, + {}, + { + fetch + } + ); + })(); + return params; +}; diff --git a/src/routes/(app)/browse/migrate/manga/[MangaID]/+page.ts b/src/routes/(app)/browse/migrate/manga/[MangaID]/+page.ts index 825fa8a..8e50112 100644 --- a/src/routes/(app)/browse/migrate/manga/[MangaID]/+page.ts +++ b/src/routes/(app)/browse/migrate/manga/[MangaID]/+page.ts @@ -6,12 +6,33 @@ import { error } from '@sveltejs/kit'; import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { getManga, getSources } from '$lib/gql/Queries'; +import { gmState } from '$lib/simpleStores.svelte'; -export const load: PageLoad = ({ params }) => { +export const load: PageLoad = ({ params, fetch }) => { const MangaID = parseInt(params.MangaID); if (isNaN(MangaID)) { error(400, 'MangaID should be a number'); } + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getManga, + { id: MangaID }, + { + fetch + } + ); + mod.client.query( + getSources, + { isNsfw: gmState.value.nsfw ? null : false }, + { + fetch + } + ); + })(); return { MangaID }; diff --git a/src/routes/(app)/browse/migrate/source/[SourceID]/+page.ts b/src/routes/(app)/browse/migrate/source/[SourceID]/+page.ts index 5027a95..f7c8d76 100644 --- a/src/routes/(app)/browse/migrate/source/[SourceID]/+page.ts +++ b/src/routes/(app)/browse/migrate/source/[SourceID]/+page.ts @@ -4,8 +4,28 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +import { browser } from '$app/environment'; +import { sourceMigrationManga, sourceMigrationSource } from '$lib/gql/Queries'; import type { PageLoad } from './$types'; -export const load: PageLoad = ({ params }) => { +export const load: PageLoad = ({ params, fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + sourceMigrationManga, + { sourceId: params.SourceID }, + { + fetch + } + ); + mod.client.query( + sourceMigrationSource, + { sourceId: params.SourceID }, + { + fetch + } + ); + })(); return params; }; diff --git a/src/routes/(app)/browse/source/[sourceID]/+layout.ts b/src/routes/(app)/browse/source/[sourceID]/+layout.ts index b0c49be..5049d22 100644 --- a/src/routes/(app)/browse/source/[sourceID]/+layout.ts +++ b/src/routes/(app)/browse/source/[sourceID]/+layout.ts @@ -5,7 +5,20 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. import type { LayoutLoad } from './$types'; +import { browser } from '$app/environment'; +import { getSource } from '$lib/gql/Queries'; -export const load: LayoutLoad = ({ params }) => { +export const load: LayoutLoad = ({ params, fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getSource, + { id: params.sourceID }, + { + fetch + } + ); + })(); return { ...params }; }; diff --git a/src/routes/(app)/browse/sources/+page.ts b/src/routes/(app)/browse/sources/+page.ts new file mode 100644 index 0000000..6944e5a --- /dev/null +++ b/src/routes/(app)/browse/sources/+page.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { getSources } from '$lib/gql/Queries'; +import { gmState } from '$lib/simpleStores.svelte'; + +export const load: PageLoad = ({ params, fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getSources, + { isNsfw: gmState.value.nsfw ? null : false }, + { + fetch + } + ); + })(); + return { ...params }; +}; diff --git a/src/routes/(app)/history/+page.ts b/src/routes/(app)/history/+page.ts new file mode 100644 index 0000000..3143e60 --- /dev/null +++ b/src/routes/(app)/history/+page.ts @@ -0,0 +1,23 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { History } from '$lib/gql/Queries'; + +export const load: PageLoad = ({ params, fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + History, + { offset: 0 }, + { + fetch + } + ); + })(); + return { ...params }; +}; diff --git a/src/routes/(app)/manga/[MangaID]/(manga)/+page.ts b/src/routes/(app)/manga/[MangaID]/(manga)/+page.ts index 242e5b7..0be75ee 100644 --- a/src/routes/(app)/manga/[MangaID]/(manga)/+page.ts +++ b/src/routes/(app)/manga/[MangaID]/(manga)/+page.ts @@ -6,11 +6,24 @@ import { error } from '@sveltejs/kit'; import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { getManga } from '$lib/gql/Queries'; -export const load: PageLoad = ({ params }) => { - const tmp = parseInt(params.MangaID); - if (isNaN(tmp)) error(400, 'MangaID should be a number'); +export const load: PageLoad = ({ params, fetch }) => { + const MangaID = parseInt(params.MangaID); + if (isNaN(MangaID)) error(400, 'MangaID should be a number'); + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getManga, + { id: MangaID }, + { + fetch + } + ); + })(); return { - MangaID: tmp + MangaID }; }; diff --git a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+layout.ts b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+layout.ts index 20cdc3d..58e15b4 100644 --- a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+layout.ts +++ b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+layout.ts @@ -6,6 +6,8 @@ import { error } from '@sveltejs/kit'; import type { LayoutLoad } from './$types'; +import { browser } from '$app/environment'; +import { fetchChapterPages } from '$lib/gql/Mutations'; export const ssr = false; export const prerender = false; @@ -15,6 +17,22 @@ export const load: LayoutLoad = ({ params }) => { const ChapterID = parseInt(params.ChapterID); if (isNaN(MangaID)) error(400, 'MangaID should be a number'); if (isNaN(ChapterID)) error(400, 'MangaID should be a number'); + if (browser) + return import('$lib/gql/graphqlClient').then((mod) => { + return { + pre: mod.client + .mutation( + fetchChapterPages, + { chapterId: ChapterID }, + { + fetch + } + ) + .toPromise(), + MangaID, + ChapterID + }; + }); return { MangaID, ChapterID diff --git a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte index 958a39a..626183c 100644 --- a/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte +++ b/src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte @@ -102,8 +102,11 @@ | Promise>> | undefined = $state(); function loadNew() { - if (preload && !pagenav) pages = preload; - else + if (preload && !$pagenav) pages = preload; + else if (preload === data.pre) { + pages = preload; + preload = undefined; + } else pages = client .mutation(fetchChapterPages, { chapterId: currentChapterID }) .toPromise(); @@ -111,7 +114,7 @@ let preload: | Promise>> - | undefined = $state(undefined); + | undefined = $state(data.pre); let preLoadingId: number | undefined = $state(undefined); async function updatePages( pages: @@ -145,8 +148,7 @@ } function getChapterAfterID( - currentID: number, - _: unknown = undefined + currentID: number ): ResultOf | undefined { const currentChapter = getChapterOfID(currentID); if (!currentChapter) return undefined; @@ -460,12 +462,7 @@ const _ = [currentChapterID]; untrack(loadNew); }); - let nextid = $derived.by(() => { - const _ = [currentChapterID]; - untrack(() => { - return getChapterAfterID(currentChapterID, manga)?.id; - }); - }); + let nextid = $derived(getChapterAfterID(currentChapterID)?.id); $effect(() => { if ( nextid !== undefined && diff --git a/src/routes/(app)/settings/about/+page.ts b/src/routes/(app)/settings/about/+page.ts new file mode 100644 index 0000000..9a0b818 --- /dev/null +++ b/src/routes/(app)/settings/about/+page.ts @@ -0,0 +1,22 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { getabout } from '$lib/gql/Queries'; + +export const load: PageLoad = ({ fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getabout, + {}, + { + fetch + } + ); + })(); +}; diff --git a/src/routes/(app)/settings/categories/+page.ts b/src/routes/(app)/settings/categories/+page.ts new file mode 100644 index 0000000..ca8b099 --- /dev/null +++ b/src/routes/(app)/settings/categories/+page.ts @@ -0,0 +1,22 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { getCategories } from '$lib/gql/Queries'; + +export const load: PageLoad = ({ fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + getCategories, + {}, + { + fetch + } + ); + })(); +}; diff --git a/src/routes/(app)/settings/server/+page.ts b/src/routes/(app)/settings/server/+page.ts new file mode 100644 index 0000000..b54c72d --- /dev/null +++ b/src/routes/(app)/settings/server/+page.ts @@ -0,0 +1,22 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { serverSettings } from '$lib/gql/Queries'; + +export const load: PageLoad = ({ fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + serverSettings, + {}, + { + fetch + } + ); + })(); +}; diff --git a/src/routes/(app)/updates/+page.ts b/src/routes/(app)/updates/+page.ts new file mode 100644 index 0000000..c3bd2c6 --- /dev/null +++ b/src/routes/(app)/updates/+page.ts @@ -0,0 +1,22 @@ +// Copyright (c) 2024 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +import type { PageLoad } from './$types'; +import { browser } from '$app/environment'; +import { updates } from '$lib/gql/Queries'; + +export const load: PageLoad = ({ fetch }) => { + if (browser) + (async () => { + const mod = await import('$lib/gql/graphqlClient'); + mod.client.query( + updates, + { offset: 0 }, + { + fetch + } + ); + })(); +};