Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
fix search
Browse files- src/lib/components/models/drawer/Drawer.svelte +6 -6
- src/routes/+page.svelte +12 -9
- src/routes/+page.ts +3 -10
src/lib/components/models/drawer/Drawer.svelte
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<script lang="ts">
|
2 |
import { clickoutside } from '@svelte-put/clickoutside';
|
3 |
-
import { goto } from "$app/navigation";
|
4 |
import { page } from "$app/stores";
|
5 |
import { get } from "svelte/store";
|
6 |
import Icon from "@iconify/svelte";
|
@@ -19,7 +19,7 @@
|
|
19 |
model = value?.model;
|
20 |
});
|
21 |
|
22 |
-
const handleClose = () => {
|
23 |
modelStore.update((value) => {
|
24 |
return {
|
25 |
...value,
|
@@ -28,7 +28,8 @@
|
|
28 |
});
|
29 |
|
30 |
$page.url.searchParams.delete('model');
|
31 |
-
goto(`?${$page.url.searchParams.toString()}`);
|
|
|
32 |
};
|
33 |
|
34 |
const handleClickNext = () => {
|
@@ -43,10 +44,9 @@
|
|
43 |
handleClose();
|
44 |
}
|
45 |
};
|
46 |
-
const handleClickAuthor = () => {
|
47 |
$page.url.searchParams.set('search', author as string);
|
48 |
-
|
49 |
-
handleClose()
|
50 |
}
|
51 |
</script>
|
52 |
|
|
|
1 |
<script lang="ts">
|
2 |
import { clickoutside } from '@svelte-put/clickoutside';
|
3 |
+
import { goto, invalidate } from "$app/navigation";
|
4 |
import { page } from "$app/stores";
|
5 |
import { get } from "svelte/store";
|
6 |
import Icon from "@iconify/svelte";
|
|
|
19 |
model = value?.model;
|
20 |
});
|
21 |
|
22 |
+
const handleClose = async () => {
|
23 |
modelStore.update((value) => {
|
24 |
return {
|
25 |
...value,
|
|
|
28 |
});
|
29 |
|
30 |
$page.url.searchParams.delete('model');
|
31 |
+
await goto(`?${$page.url.searchParams.toString()}`);
|
32 |
+
await invalidate(url => url.pathname.includes("/api/models"));
|
33 |
};
|
34 |
|
35 |
const handleClickNext = () => {
|
|
|
44 |
handleClose();
|
45 |
}
|
46 |
};
|
47 |
+
const handleClickAuthor = async () => {
|
48 |
$page.url.searchParams.set('search', author as string);
|
49 |
+
handleClose();
|
|
|
50 |
}
|
51 |
</script>
|
52 |
|
src/routes/+page.svelte
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
<script lang="ts">
|
2 |
import { browser } from "$app/environment";
|
3 |
import InfiniteScroll from "svelte-infinite-scroll";
|
|
|
|
|
|
|
4 |
import Button from "$lib/components/Button.svelte";
|
5 |
import Card from "$lib/components/models/Card.svelte";
|
6 |
import Input from "$lib/components/fields/Input.svelte";
|
@@ -10,13 +13,10 @@
|
|
10 |
import Dialog from "$lib/components/dialog/Dialog.svelte";
|
11 |
import SubmitModel from "$lib/components/models/Submit.svelte";
|
12 |
import Drawer from "$lib/components/models/drawer/Drawer.svelte";
|
13 |
-
import { page } from "$app/stores";
|
14 |
-
import { goto } from "$app/navigation";
|
15 |
-
// import UserIsLogged from "$lib/components/UserIsLogged.svelte";
|
16 |
|
17 |
export let data
|
18 |
|
19 |
-
|
20 |
filter: data?.filter,
|
21 |
search: data?.search,
|
22 |
page: "0",
|
@@ -30,18 +30,18 @@
|
|
30 |
refetch(true);
|
31 |
}
|
32 |
const handleChangeFilter = async (filter: string) => {
|
33 |
-
form = { ...form, filter, page: (0).toString()};
|
34 |
$page.url.searchParams.set('filter', filter);
|
35 |
-
goto(`?${$page.url.searchParams.toString()}
|
|
|
36 |
}
|
37 |
let timeout: any;
|
38 |
const handleChangeSearch = async (search: string) => {
|
39 |
clearTimeout(timeout);
|
40 |
-
|
41 |
-
timeout = setTimeout(() => {
|
42 |
if (search === "") $page.url.searchParams.delete('search');
|
43 |
else $page.url.searchParams.set('search', search);
|
44 |
-
goto(`?${$page.url.searchParams.toString()}
|
|
|
45 |
}, 500);
|
46 |
}
|
47 |
|
@@ -107,6 +107,9 @@
|
|
107 |
{#each data.models as card}
|
108 |
<Card card={card} />
|
109 |
{/each}
|
|
|
|
|
|
|
110 |
<InfiniteScroll
|
111 |
elementScroll="{elementScroll ?? undefined}"
|
112 |
threshold={100}
|
|
|
1 |
<script lang="ts">
|
2 |
import { browser } from "$app/environment";
|
3 |
import InfiniteScroll from "svelte-infinite-scroll";
|
4 |
+
import { page } from "$app/stores";
|
5 |
+
|
6 |
+
import { goto, invalidate } from "$app/navigation";
|
7 |
import Button from "$lib/components/Button.svelte";
|
8 |
import Card from "$lib/components/models/Card.svelte";
|
9 |
import Input from "$lib/components/fields/Input.svelte";
|
|
|
13 |
import Dialog from "$lib/components/dialog/Dialog.svelte";
|
14 |
import SubmitModel from "$lib/components/models/Submit.svelte";
|
15 |
import Drawer from "$lib/components/models/drawer/Drawer.svelte";
|
|
|
|
|
|
|
16 |
|
17 |
export let data
|
18 |
|
19 |
+
$: form = {
|
20 |
filter: data?.filter,
|
21 |
search: data?.search,
|
22 |
page: "0",
|
|
|
30 |
refetch(true);
|
31 |
}
|
32 |
const handleChangeFilter = async (filter: string) => {
|
|
|
33 |
$page.url.searchParams.set('filter', filter);
|
34 |
+
await goto(`?${$page.url.searchParams.toString()}`);
|
35 |
+
await invalidate(url => url.pathname.includes("/api/models"));
|
36 |
}
|
37 |
let timeout: any;
|
38 |
const handleChangeSearch = async (search: string) => {
|
39 |
clearTimeout(timeout);
|
40 |
+
timeout = setTimeout(async () => {
|
|
|
41 |
if (search === "") $page.url.searchParams.delete('search');
|
42 |
else $page.url.searchParams.set('search', search);
|
43 |
+
await goto(`?${$page.url.searchParams.toString()}`);
|
44 |
+
await invalidate(url => url.pathname.includes("/api/models"));
|
45 |
}, 500);
|
46 |
}
|
47 |
|
|
|
107 |
{#each data.models as card}
|
108 |
<Card card={card} />
|
109 |
{/each}
|
110 |
+
{#if data.models.length === 0}
|
111 |
+
<p class="text-neutral-400 text-left w-full">No models found</p>
|
112 |
+
{/if}
|
113 |
<InfiniteScroll
|
114 |
elementScroll="{elementScroll ?? undefined}"
|
115 |
threshold={100}
|
src/routes/+page.ts
CHANGED
@@ -4,7 +4,8 @@ import { modelStore } from "$lib/stores/use-model";
|
|
4 |
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") ??
|
|
|
8 |
|
9 |
if (model_param) {
|
10 |
const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
|
@@ -20,14 +21,7 @@ export async function load({ fetch, url }) {
|
|
20 |
});
|
21 |
}
|
22 |
|
23 |
-
|
24 |
-
const data = {
|
25 |
-
filter: filter_param ?? "hotest",
|
26 |
-
page: "0",
|
27 |
-
search: search_param ?? ""
|
28 |
-
}
|
29 |
-
|
30 |
-
const response = await fetch(`/api/models?${new URLSearchParams(data)}`, {
|
31 |
method: "GET",
|
32 |
headers: {
|
33 |
"Content-Type": "application/json"
|
@@ -39,6 +33,5 @@ export async function load({ fetch, url }) {
|
|
39 |
total_items: models?.total_items ?? 0,
|
40 |
search: search_param ?? "",
|
41 |
filter: filter_param,
|
42 |
-
// model: model?.model ?? null
|
43 |
}
|
44 |
}
|
|
|
4 |
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`, {
|
|
|
21 |
});
|
22 |
}
|
23 |
|
24 |
+
const response = await fetch(`/api/models${url.search}`, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
method: "GET",
|
26 |
headers: {
|
27 |
"Content-Type": "application/json"
|
|
|
33 |
total_items: models?.total_items ?? 0,
|
34 |
search: search_param ?? "",
|
35 |
filter: filter_param,
|
|
|
36 |
}
|
37 |
}
|