enzostvs HF staff commited on
Commit
9445ddf
β€’
1 Parent(s): 9601c9e

fix: click on model doesnt display drawer

Browse files
src/lib/components/models/Card.svelte CHANGED
@@ -1,18 +1,19 @@
1
  <script lang="ts">
2
  import type { ModelCard } from "$lib/type";
3
  import Icon from "@iconify/svelte";
4
- import { goto } from "$app/navigation";
5
  import { page } from "$app/stores";
6
  import Button from "$lib/components/Button.svelte";
7
  import { success } from "$lib/utils/toaster";
8
  import { userStore } from "$lib/stores/use-user";
9
 
10
  export let card: ModelCard;
11
-
12
 
13
  const handleClick = async () => {
14
  $page.url.searchParams.set('model', card?.id);
15
  goto(`?${$page.url.searchParams.toString()}`);
 
16
  };
17
 
18
  const publish = async () => {
 
1
  <script lang="ts">
2
  import type { ModelCard } from "$lib/type";
3
  import Icon from "@iconify/svelte";
4
+ import { goto, invalidate } from "$app/navigation";
5
  import { page } from "$app/stores";
6
  import Button from "$lib/components/Button.svelte";
7
  import { success } from "$lib/utils/toaster";
8
  import { userStore } from "$lib/stores/use-user";
9
 
10
  export let card: ModelCard;
11
+ export let onClick: (modelId: string) => void;
12
 
13
  const handleClick = async () => {
14
  $page.url.searchParams.set('model', card?.id);
15
  goto(`?${$page.url.searchParams.toString()}`);
16
+ onClick(card?.id);
17
  };
18
 
19
  const publish = async () => {
src/routes/+page.svelte CHANGED
@@ -2,6 +2,7 @@
2
  import { browser } from "$app/environment";
3
  import InfiniteScroll from "svelte-infinite-scroll";
4
  import { page } from "$app/stores";
 
5
 
6
  import { goto } from "$app/navigation";
7
  import Button from "$lib/components/Button.svelte";
@@ -35,6 +36,9 @@
35
 
36
  onMount(() => {
37
  refetch(false);
 
 
 
38
  });
39
 
40
  $: elementScroll = browser ? document?.getElementById('app') : undefined;
@@ -71,7 +75,21 @@
71
  data.models = response.cards;
72
  data.total_items = response.total_items;
73
  }
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  </script>
76
 
77
  <svelte:head>
@@ -135,7 +153,7 @@
135
  </div>
136
  <div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
137
  {#each data.models as card}
138
- <Card card={card} />
139
  {/each}
140
  {#if data.models.length === 0}
141
  <p class="text-neutral-400 text-left w-full">No models found</p>
 
2
  import { browser } from "$app/environment";
3
  import InfiniteScroll from "svelte-infinite-scroll";
4
  import { page } from "$app/stores";
5
+ import { modelStore } from "$lib/stores/use-model";
6
 
7
  import { goto } from "$app/navigation";
8
  import Button from "$lib/components/Button.svelte";
 
36
 
37
  onMount(() => {
38
  refetch(false);
39
+ if ($page.url.searchParams.get('model')) {
40
+ getModel($page.url.searchParams.get('model') as string);
41
+ }
42
  });
43
 
44
  $: elementScroll = browser ? document?.getElementById('app') : undefined;
 
75
  data.models = response.cards;
76
  data.total_items = response.total_items;
77
  }
78
+ }
79
+
80
+ const getModel = async (modelId: string) => {
81
+ const model_request = await fetch(`/api/models/${modelId?.replace("/", "@")}?full=true`, {
82
+ method: "GET",
83
+ headers: {
84
+ "Content-Type": "application/json"
85
+ }
86
+ })
87
+ const data = await model_request?.clone().json().catch(() => null);
88
+ modelStore.set({
89
+ model: data?.model ?? null,
90
+ open: true
91
+ });
92
+ }
93
  </script>
94
 
95
  <svelte:head>
 
153
  </div>
154
  <div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
155
  {#each data.models as card}
156
+ <Card card={card} onClick={getModel} />
157
  {/each}
158
  {#if data.models.length === 0}
159
  <p class="text-neutral-400 text-left w-full">No models found</p>
src/routes/+page.ts DELETED
@@ -1,22 +0,0 @@
1
- import { modelStore } from "$lib/stores/use-model";
2
-
3
- /** @type {import('./$types').PageServerLoad} */
4
- export async function load({ fetch, url }) {
5
- const model_param = url.searchParams.get("model")
6
-
7
- if (model_param) {
8
- const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
9
- method: "GET",
10
- headers: {
11
- "Content-Type": "application/json"
12
- }
13
- })
14
- const data = await model_request?.clone().json().catch(() => null);
15
- modelStore.set({
16
- model: data?.model ?? null,
17
- open: true
18
- });
19
- }
20
- return {
21
- }
22
- }