Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
pagination error
Browse files- src/routes/+page.svelte +4 -4
- src/routes/+page.ts +0 -1
- src/routes/api/models/+server.ts +1 -1
src/routes/+page.svelte
CHANGED
@@ -19,14 +19,14 @@
|
|
19 |
$: form = {
|
20 |
filter: data?.filter,
|
21 |
search: data?.search,
|
22 |
-
page: "0",
|
23 |
}
|
|
|
24 |
let submitModelDialog = false;
|
25 |
|
26 |
$: elementScroll = browser ? document?.getElementById('app') : undefined;
|
27 |
|
28 |
const handleFetchMore = async () => {
|
29 |
-
|
30 |
refetch(true);
|
31 |
}
|
32 |
const handleChangeFilter = async (filter: string) => {
|
@@ -46,9 +46,9 @@
|
|
46 |
}
|
47 |
|
48 |
const refetch = async (add: boolean) => {
|
49 |
-
const request = await fetch(`/api/models?${new URLSearchParams(form)}`);
|
50 |
const response = await request.json();
|
51 |
-
if (add) data = {...data, models: [...data.models, ...response.cards
|
52 |
else {
|
53 |
data.models = response.cards;
|
54 |
data.total_items = response.total_items;
|
|
|
19 |
$: form = {
|
20 |
filter: data?.filter,
|
21 |
search: data?.search,
|
|
|
22 |
}
|
23 |
+
let current_page = "0";
|
24 |
let submitModelDialog = false;
|
25 |
|
26 |
$: elementScroll = browser ? document?.getElementById('app') : undefined;
|
27 |
|
28 |
const handleFetchMore = async () => {
|
29 |
+
current_page = (Number(current_page) + 1).toString();
|
30 |
refetch(true);
|
31 |
}
|
32 |
const handleChangeFilter = async (filter: string) => {
|
|
|
46 |
}
|
47 |
|
48 |
const refetch = async (add: boolean) => {
|
49 |
+
const request = await fetch(`/api/models?${new URLSearchParams({...form, page: current_page })}`);
|
50 |
const response = await request.json();
|
51 |
+
if (add) data = {...data, models: [...data.models, ...response.cards]};
|
52 |
else {
|
53 |
data.models = response.cards;
|
54 |
data.total_items = response.total_items;
|
src/routes/+page.ts
CHANGED
@@ -5,7 +5,6 @@ export async function load({ fetch, url }) {
|
|
5 |
const model_param = url.searchParams.get("model")
|
6 |
const search_param = url.searchParams.get("search") ?? undefined
|
7 |
const filter_param = url.searchParams.get("filter") ?? "hotest"
|
8 |
-
|
9 |
|
10 |
if (model_param) {
|
11 |
const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
|
|
|
5 |
const model_param = url.searchParams.get("model")
|
6 |
const search_param = url.searchParams.get("search") ?? undefined
|
7 |
const filter_param = url.searchParams.get("filter") ?? "hotest"
|
|
|
8 |
|
9 |
if (model_param) {
|
10 |
const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
|
src/routes/api/models/+server.ts
CHANGED
@@ -31,7 +31,7 @@ export async function GET(request : RequestEvent) {
|
|
31 |
orderBy: {
|
32 |
...(filter === 'hotest' ? { downloads: 'desc' } : filter === 'likes' ? { likes: 'desc' } : { createdAt: 'desc' })
|
33 |
},
|
34 |
-
skip:
|
35 |
take: limit,
|
36 |
})
|
37 |
|
|
|
31 |
orderBy: {
|
32 |
...(filter === 'hotest' ? { downloads: 'desc' } : filter === 'likes' ? { likes: 'desc' } : { createdAt: 'desc' })
|
33 |
},
|
34 |
+
skip: page * limit,
|
35 |
take: limit,
|
36 |
})
|
37 |
|