Skip to content

Commit

Permalink
pre load init page data
Browse files Browse the repository at this point in the history
  • Loading branch information
Robonau authored and Robonau committed Nov 9, 2024
1 parent 6bdc985 commit 9463ae9
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 18 deletions.
25 changes: 25 additions & 0 deletions src/routes/(app)/(library)/+page.ts
Original file line number Diff line number Diff line change
@@ -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 });
})();
};
24 changes: 24 additions & 0 deletions src/routes/(app)/browse/extensions/+page.ts
Original file line number Diff line number Diff line change
@@ -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
}
);
})();
};
24 changes: 24 additions & 0 deletions src/routes/(app)/browse/globalsearch/+page.ts
Original file line number Diff line number Diff line change
@@ -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
}
);
})();
};
23 changes: 23 additions & 0 deletions src/routes/(app)/browse/migrate/+page.ts
Original file line number Diff line number Diff line change
@@ -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;
};
23 changes: 22 additions & 1 deletion src/routes/(app)/browse/migrate/manga/[MangaID]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
22 changes: 21 additions & 1 deletion src/routes/(app)/browse/migrate/source/[SourceID]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
15 changes: 14 additions & 1 deletion src/routes/(app)/browse/source/[sourceID]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
24 changes: 24 additions & 0 deletions src/routes/(app)/browse/sources/+page.ts
Original file line number Diff line number Diff line change
@@ -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 };
};
23 changes: 23 additions & 0 deletions src/routes/(app)/history/+page.ts
Original file line number Diff line number Diff line change
@@ -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 };
};
21 changes: 17 additions & 4 deletions src/routes/(app)/manga/[MangaID]/(manga)/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};
18 changes: 18 additions & 0 deletions src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
19 changes: 8 additions & 11 deletions src/routes/(app)/manga/[MangaID]/chapter/[ChapterID]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,19 @@
| Promise<OperationResult<ResultOf<typeof fetchChapterPages>>>
| 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();
}
let preload:
| Promise<OperationResult<ResultOf<typeof fetchChapterPages>>>
| undefined = $state(undefined);
| undefined = $state(data.pre);
let preLoadingId: number | undefined = $state(undefined);
async function updatePages(
pages:
Expand Down Expand Up @@ -145,8 +148,7 @@
}
function getChapterAfterID(
currentID: number,
_: unknown = undefined
currentID: number
): ResultOf<typeof ChapterTypeFragment> | undefined {
const currentChapter = getChapterOfID(currentID);
if (!currentChapter) return undefined;
Expand Down Expand Up @@ -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 &&
Expand Down
22 changes: 22 additions & 0 deletions src/routes/(app)/settings/about/+page.ts
Original file line number Diff line number Diff line change
@@ -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
}
);
})();
};
22 changes: 22 additions & 0 deletions src/routes/(app)/settings/categories/+page.ts
Original file line number Diff line number Diff line change
@@ -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
}
);
})();
};
Loading

0 comments on commit 9463ae9

Please sign in to comment.