enzostvs HF staff commited on
Commit
a084673
β€’
1 Parent(s): c479a59
src/lib/components/Button.svelte CHANGED
@@ -50,6 +50,9 @@ import { goto } from '$app/navigation';
50
  &.pink {
51
  @apply bg-pink-500 text-white border-pink-500;
52
  }
 
 
 
53
  &.dark {
54
  @apply bg-neutral-900 border-neutral-800 text-neutral-300;
55
  }
 
50
  &.pink {
51
  @apply bg-pink-500 text-white border-pink-500;
52
  }
53
+ &.blue {
54
+ @apply bg-blue-500 text-white border-blue-500;
55
+ }
56
  &.dark {
57
  @apply bg-neutral-900 border-neutral-800 text-neutral-300;
58
  }
src/lib/utils/index.ts CHANGED
@@ -13,4 +13,19 @@ export const COMMUNITY_FILTER_OPTIONS = [
13
  icon: "lucide:zap",
14
  iconColor: "text-yellow-500"
15
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  ];
 
13
  icon: "lucide:zap",
14
  iconColor: "text-yellow-500"
15
  },
16
+ ];
17
+
18
+ export const MODELS_FILTER_OPTIONS = [
19
+ {
20
+ label: "Most Liked",
21
+ value: "likes",
22
+ icon: "lucide:heart",
23
+ iconColor: "text-red-500"
24
+ },
25
+ {
26
+ label: "Hotest",
27
+ value: "hot",
28
+ icon: "ph:fire-bold",
29
+ iconColor: "text-orange-500"
30
+ },
31
  ];
src/routes/+layout.svelte CHANGED
@@ -1,6 +1,6 @@
1
  <script>
2
  import Sidebar from "$lib/components/sidebar/Sidebar.svelte";
3
- import "$lib/styles/tailwind.css"
4
  </script>
5
 
6
  <div class="flex items-start">
 
1
  <script>
2
  import Sidebar from "$lib/components/sidebar/Sidebar.svelte";
3
+ import "$lib/styles/tailwind.css"
4
  </script>
5
 
6
  <div class="flex items-start">
src/routes/+page.svelte CHANGED
@@ -20,9 +20,9 @@
20
 
21
  const fetchMore = async () => {
22
  form = {...form, page: (Number(form.page) + 1).toString()};
23
- const response = await fetch(`/api/community?${new URLSearchParams(form)}`);
24
- const new_cards = await response.json();
25
- data = {...data, cards: [...data.cards, ...new_cards]};
26
  }
27
  </script>
28
 
@@ -36,21 +36,26 @@
36
  </h1>
37
  <div class="flex items-center justify-between mt-5">
38
  <Radio options={COMMUNITY_FILTER_OPTIONS} value="{form.filter}" onChange={(filter) => form = {...form, filter }} />
39
- <div class="flex items-center justify-end gap-5">
40
  <Button icon="ic:round-plus" theme="dark" size="lg">Upload own Image</Button>
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 max-w-sm">
45
  <Input placeholder="Filter by prompt, model..." />
46
  </div>
47
- <div class="mx-auto grid grid-cols-5 gap-5 mt-8 lg:mt-10">
48
  {#each data.cards as card}
49
  <Card card={card} />
50
  {/each}
51
  <InfiniteScroll
52
  elementScroll="{elementScroll ?? undefined}"
53
  threshold={100}
 
54
  on:loadMore={fetchMore}
55
  />
56
  <GoTop />
 
20
 
21
  const fetchMore = async () => {
22
  form = {...form, page: (Number(form.page) + 1).toString()};
23
+ const request = await fetch(`/api/community?${new URLSearchParams(form)}`);
24
+ const response = await request.json();
25
+ data = {...data, cards: [...data.cards, ...response.cards ]};
26
  }
27
  </script>
28
 
 
36
  </h1>
37
  <div class="flex items-center justify-between mt-5">
38
  <Radio options={COMMUNITY_FILTER_OPTIONS} value="{form.filter}" onChange={(filter) => form = {...form, filter }} />
39
+ <div class="items-center justify-end gap-5 hidden lg:flex">
40
  <Button icon="ic:round-plus" theme="dark" size="lg">Upload own Image</Button>
41
  <Button icon="fluent:glance-horizontal-sparkles-16-filled" href="/generate" theme="pink" size="lg">Generate</Button>
42
  </div>
43
+ <div class="items-center justify-end gap-3 flex lg:hidden">
44
+ <Button icon="ic:round-plus" theme="dark" size="md">Upload own Image</Button>
45
+ <Button icon="fluent:glance-horizontal-sparkles-16-filled" href="/generate" theme="pink" size="md">Generate</Button>
46
+ </div>
47
  </div>
48
  <div class="mt-5 max-w-sm">
49
  <Input placeholder="Filter by prompt, model..." />
50
  </div>
51
+ <div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-5 gap-5 mt-8 lg:mt-10">
52
  {#each data.cards as card}
53
  <Card card={card} />
54
  {/each}
55
  <InfiniteScroll
56
  elementScroll="{elementScroll ?? undefined}"
57
  threshold={100}
58
+ hasMore={data.total_items > data.cards.length}
59
  on:loadMore={fetchMore}
60
  />
61
  <GoTop />
src/routes/+page.ts CHANGED
@@ -1,10 +1,10 @@
1
  export async function load({ fetch }) {
2
- const data = await fetch("/api/community?page=1", {
3
  method: "GET",
4
  headers: {
5
  "Content-Type": "application/json"
6
  }
7
  })
8
- const cards = await data.json()
9
- return { cards }
10
  }
 
1
  export async function load({ fetch }) {
2
+ const response = await fetch("/api/community?page=1", {
3
  method: "GET",
4
  headers: {
5
  "Content-Type": "application/json"
6
  }
7
  })
8
+ const data = await response.json()
9
+ return data
10
  }
src/routes/api/community/+server.ts CHANGED
@@ -15,5 +15,8 @@ export async function GET(request : RequestEvent) {
15
 
16
  const cards = jsonData.slice(page * 25, page * 25 + 25)
17
 
18
- return json(cards)
 
 
 
19
  }
 
15
 
16
  const cards = jsonData.slice(page * 25, page * 25 + 25)
17
 
18
+ return json({
19
+ cards,
20
+ total_items: jsonData.length,
21
+ })
22
  }
src/routes/models/+page.svelte CHANGED
@@ -1,8 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <svelte:head>
2
- <title>Explore models</title>
3
  <meta name="description" content="Svelte demo app" />
4
  </svelte:head>
5
 
6
  <h1 class="text-white font-semibold text-2xl">
7
- Explore models
8
- </h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { browser } from "$app/environment";
3
+ import InfiniteScroll from "svelte-infinite-scroll";
4
+
5
+ import Button from "$lib/components/Button.svelte";
6
+ import Card from "$lib/components/community/Card.svelte";
7
+ import Input from "$lib/components/fields/Input.svelte";
8
+ import Radio from "$lib/components/fields/Radio.svelte";
9
+ import { MODELS_FILTER_OPTIONS } from "$lib/utils/index.js";
10
+ import GoTop from "$lib/components/GoTop.svelte";
11
+
12
+ export let data;
13
+
14
+ let form = {
15
+ filter: "hot",
16
+ page: "0",
17
+ }
18
+
19
+ $: elementScroll = browser ? document?.getElementById('app') : undefined;
20
+
21
+ const fetchMore = async () => {
22
+ form = {...form, page: (Number(form.page) + 1).toString()};
23
+ const request = await fetch(`/api/community?${new URLSearchParams(form)}`);
24
+ const response = await request.json();
25
+ data = {...data, cards: [...data.cards, ...response.cards ]};
26
+ }
27
+ </script>
28
+
29
  <svelte:head>
30
+ <title>Explore Models</title>
31
  <meta name="description" content="Svelte demo app" />
32
  </svelte:head>
33
 
34
  <h1 class="text-white font-semibold text-2xl">
35
+ Explore Models
36
+ </h1>
37
+ <div class="flex items-center justify-between mt-5">
38
+ <Radio options={MODELS_FILTER_OPTIONS} value="{form.filter}" onChange={(filter) => form = {...form, filter }} />
39
+ <div class="items-center justify-end gap-5 hidden lg:flex">
40
+ <Button icon="ic:round-plus" theme="dark" size="lg">Create</Button>
41
+ <Button icon="octicon:upload-16" theme="blue" size="lg">Upload model</Button>
42
+ </div>
43
+ <div class="items-center justify-end gap-3 flex lg:hidden">
44
+ <Button icon="ic:round-plus" theme="dark" size="md">Create</Button>
45
+ <Button icon="octicon:upload-16" theme="blue" size="md">Upload model</Button>
46
+ </div>
47
+ </div>
48
+ <div class="mt-5 max-w-sm">
49
+ <Input placeholder="Search a model" />
50
+ </div>
51
+ <div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-5 gap-5 mt-8 lg:mt-10">
52
+ {#each data.cards as card}
53
+ <Card card={card} />
54
+ {/each}
55
+ <InfiniteScroll
56
+ elementScroll="{elementScroll ?? undefined}"
57
+ threshold={100}
58
+ hasMore={data.total_items > data.cards.length}
59
+ on:loadMore={fetchMore}
60
+ />
61
+ <GoTop />
62
+ </div>
src/routes/models/+page.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ export async function load({ fetch }) {
2
+ const response = await fetch("/api/community?page=1", {
3
+ method: "GET",
4
+ headers: {
5
+ "Content-Type": "application/json"
6
+ }
7
+ })
8
+ const data = await response.json()
9
+ return data
10
+ }