enzostvs HF staff commited on
Commit
97ec6f2
β€’
1 Parent(s): dd7ec11

wip API get

Browse files
src/lib/components/community/Card.svelte CHANGED
@@ -1,24 +1,25 @@
1
  <script lang="ts">
2
- import { REACTION_EMOJIS } from "$lib/utils";
3
  import Reaction from "$lib/components/community/reactions/Reaction.svelte";
4
  import Add from "$lib/components/community/reactions/Add.svelte";
 
 
 
5
 
6
- $: reactions = REACTION_EMOJIS.sort(() => Math.random() - Math.random()).slice(0, 3);
7
  </script>
8
 
9
  <div
10
  class="cursor-pointer group bg-neutral-700 rounded-xl h-[310px] relative flex items-start justify-between flex-col p-5 transition-all duration-200 brightness-75 hover:brightness-100 z-[1]"
11
  >
12
  <div class="w-full h-full absolute top-0 left-0 -z-[1] rounded-xl overflow-hidden">
13
- <div class="w-full h-full bg-center bg-cover transition-all duration-200 group-hover:scale-110 " style="background-image: url('https://images.unsplash.com/photo-1682687220015-186f63b8850a?q=80&w=4075&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D');"></div>
14
  </div>
15
  <div class="bg-black/40 backdrop-blur-sm border border-white/30 rounded-lg px-6 py-3 text-white transition-all duration-200 opacity-0 group-hover:opacity-100">
16
- <p class="text-white font-semibold text-base">A mini hamster in a wheat field</p>
17
- <p class="text-white/75 font-regular text-sm">LoRA model name</p>
18
  </div>
19
  <div class="flex items-center justify-start gap-2">
20
- {#each reactions as emoji}
21
- <Reaction emoji={emoji} count={Math.floor(Math.random() * 100)} />
22
  {/each}
23
  <Add />
24
  </div>
 
1
  <script lang="ts">
 
2
  import Reaction from "$lib/components/community/reactions/Reaction.svelte";
3
  import Add from "$lib/components/community/reactions/Add.svelte";
4
+ import type { CommunityCard } from "$lib/type";
5
+
6
+ export let card: CommunityCard;
7
 
 
8
  </script>
9
 
10
  <div
11
  class="cursor-pointer group bg-neutral-700 rounded-xl h-[310px] relative flex items-start justify-between flex-col p-5 transition-all duration-200 brightness-75 hover:brightness-100 z-[1]"
12
  >
13
  <div class="w-full h-full absolute top-0 left-0 -z-[1] rounded-xl overflow-hidden">
14
+ <div class="w-full h-full bg-center bg-cover transition-all duration-200 group-hover:scale-110 " style="background-image: url('{card.image}');"></div>
15
  </div>
16
  <div class="bg-black/40 backdrop-blur-sm border border-white/30 rounded-lg px-6 py-3 text-white transition-all duration-200 opacity-0 group-hover:opacity-100">
17
+ <p class="text-white font-semibold text-base">{card.prompt}</p>
18
+ <p class="text-white/75 font-regular text-sm">{card.model_name}</p>
19
  </div>
20
  <div class="flex items-center justify-start gap-2">
21
+ {#each card.reactions as reaction}
22
+ <Reaction emoji={reaction.emoji} count={reaction?.users?.length} />
23
  {/each}
24
  <Add />
25
  </div>
src/lib/type.ts CHANGED
@@ -3,4 +3,17 @@ export interface OptionRadio {
3
  value: string;
4
  icon?: string
5
  iconColor?: string
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  }
 
3
  value: string;
4
  icon?: string
5
  iconColor?: string
6
+ }
7
+
8
+ export interface CommunityCard {
9
+ reactions: ReactionType[],
10
+ id: string,
11
+ model_name: string,
12
+ prompt: string,
13
+ image: string,
14
+ }
15
+
16
+ export interface ReactionType {
17
+ emoji: string
18
+ users: string[]
19
  }
src/routes/+page.svelte CHANGED
@@ -3,7 +3,8 @@
3
  import Card from "$lib/components/community/Card.svelte";
4
  import Input from "$lib/components/fields/Input.svelte";
5
  import Radio from "$lib/components/fields/Radio.svelte";
6
- import Icon from "@iconify/svelte";
 
7
 
8
  let form = {
9
  filter: "likes"
@@ -41,11 +42,11 @@
41
  <Button icon="fluent:glance-horizontal-sparkles-16-filled" href="/generate" theme="pink" size="lg">Generate</Button>
42
  </div>
43
  </div>
44
- <div class="mt-5">
45
- <Input />
46
  </div>
47
  <div class="mx-auto grid grid-cols-5 gap-5 mt-8 lg:mt-10">
48
- {#each Array(40) as _, i}
49
- <Card />
50
  {/each}
51
  </div>
 
3
  import Card from "$lib/components/community/Card.svelte";
4
  import Input from "$lib/components/fields/Input.svelte";
5
  import Radio from "$lib/components/fields/Radio.svelte";
6
+
7
+ export let data;
8
 
9
  let form = {
10
  filter: "likes"
 
42
  <Button icon="fluent:glance-horizontal-sparkles-16-filled" href="/generate" theme="pink" size="lg">Generate</Button>
43
  </div>
44
  </div>
45
+ <div class="mt-5 max-w-sm">
46
+ <Input placeholder="Filter by prompt, model..." />
47
  </div>
48
  <div class="mx-auto grid grid-cols-5 gap-5 mt-8 lg:mt-10">
49
+ {#each data.cards as card}
50
+ <Card card={card} />
51
  {/each}
52
  </div>
src/routes/+page.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ export async function load({ fetch }) {
2
+ const data = await fetch("/api/community")
3
+ const cards = await data.json()
4
+ return { cards }
5
+ }
src/routes/api/community/+server.ts ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { error, json } from '@sveltejs/kit';
2
+ // import { env } from '$env/dynamic/private'
3
+
4
+ import type { CommunityCard } from '$lib/type';
5
+ import { REACTION_EMOJIS } from "$lib/utils";
6
+
7
+ /** @type {import('./$types').RequestHandler} */
8
+
9
+ export async function GET() {
10
+ const hasError = false
11
+
12
+ const cards: CommunityCard[] = Array.from({ length: 50 }, (_, i) => ({
13
+ reactions: REACTION_EMOJIS.sort(() => Math.random() - Math.random()).slice(0,
14
+ Math.floor(Math.random() * REACTION_EMOJIS.length)
15
+ ).map((emoji) => ({
16
+ emoji,
17
+ users: Array.from({ length: Math.floor(Math.random() * 10) }, (_, i) => i.toString()),
18
+ })),
19
+ id: i.toString(),
20
+ model_name: "CommunityCard",
21
+ prompt: "What is your favorite color?",
22
+ image: "https://picsum.photos/seed/" + i + "/500/500",
23
+ }))
24
+
25
+ if (hasError) {
26
+ return error(500, 'Internal Server Error')
27
+ }
28
+
29
+ return json(cards)
30
+ }