enzostvs HF staff commited on
Commit
0d4cbee
β€’
1 Parent(s): 1003d95

drawer gallery view + WIP: redo the response check, user is able to post multiple time the same img

Browse files
src/lib/components/community/viewer/Viewer.svelte CHANGED
@@ -71,8 +71,8 @@
71
  {#if gallery?.id}
72
  <img src={env.PUBLIC_FILE_UPLOAD_DIR}/{gallery?.image} alt={gallery?.prompt} class="w-full object-cover h-[200px] lg:h-auto" />
73
  <div class="flex flex-col justify-between w-full overflow-auto flex-1">
74
- <div class="w-full p-8">
75
- <header class="w-full flex items-start justify-between">
76
  <div class="flex items-center justify-start gap-4">
77
  <img src={gallery?.user?.picture} class="w-12 h-12 rounded-full object-cover" alt={gallery?.user?.name} />
78
  <div>
@@ -89,10 +89,12 @@
89
  </button>
90
  </header>
91
  <div class="mt-8 grid grid-cols-1 gap-5 overflow-auto">
92
- <Reactions reactions={gallery?.reactions} gallery_id={gallery.id} />
 
 
93
  <div>
94
  <button
95
- class="flex items-center justify-start gap-4 cursor-pointer w-full text-left transition-all duration-200 hover:bg-neutral-950/50 py-3 pr-3 pl-6 -mx-3 group relative"
96
  on:click={() => handleClickModel(gallery?.model?.id)}
97
  >
98
  <img src={gallery?.model?.image} alt={gallery?.model?.title} class="w-14 h-14 rounded-lg object-cover" />
@@ -105,13 +107,13 @@
105
  </div>
106
  </button>
107
  </div>
108
- <div>
109
  <p class="text-neutral-400 font-semibold text-xs uppercase">
110
  Prompt
111
  </p>
112
  <p class="text-neutral-200 text-base font-medium mt-2">"{gallery?.prompt}"</p>
113
  </div>
114
- <div>
115
  <p class="text-neutral-400 font-semibold text-xs uppercase">
116
  Dimension
117
  </p>
 
71
  {#if gallery?.id}
72
  <img src={env.PUBLIC_FILE_UPLOAD_DIR}/{gallery?.image} alt={gallery?.prompt} class="w-full object-cover h-[200px] lg:h-auto" />
73
  <div class="flex flex-col justify-between w-full overflow-auto flex-1">
74
+ <div class="w-full p-6">
75
+ <header class="w-full flex items-start justify-between px-2 pt-2">
76
  <div class="flex items-center justify-start gap-4">
77
  <img src={gallery?.user?.picture} class="w-12 h-12 rounded-full object-cover" alt={gallery?.user?.name} />
78
  <div>
 
89
  </button>
90
  </header>
91
  <div class="mt-8 grid grid-cols-1 gap-5 overflow-auto">
92
+ <div class="w-full px-2">
93
+ <Reactions reactions={gallery?.reactions} gallery_id={gallery.id} />
94
+ </div>
95
  <div>
96
  <button
97
+ class="flex items-center justify-start gap-4 cursor-pointer w-full text-left transition-all duration-200 hover:bg-neutral-950/50 p-3 group relative rounded-lg"
98
  on:click={() => handleClickModel(gallery?.model?.id)}
99
  >
100
  <img src={gallery?.model?.image} alt={gallery?.model?.title} class="w-14 h-14 rounded-lg object-cover" />
 
107
  </div>
108
  </button>
109
  </div>
110
+ <div class="px-2">
111
  <p class="text-neutral-400 font-semibold text-xs uppercase">
112
  Prompt
113
  </p>
114
  <p class="text-neutral-200 text-base font-medium mt-2">"{gallery?.prompt}"</p>
115
  </div>
116
+ <div class="px-2">
117
  <p class="text-neutral-400 font-semibold text-xs uppercase">
118
  Dimension
119
  </p>
src/lib/components/models/drawer/Drawer.svelte CHANGED
@@ -9,6 +9,7 @@
9
  import UserIsLogged from '$lib/components/UserIsLogged.svelte';
10
  import Comments from '$lib/components/models/drawer/comments/Comments.svelte';
11
  import { env } from '$env/dynamic/public';
 
12
 
13
  let { open, model } = get(modelStore);
14
 
@@ -28,8 +29,15 @@
28
  $page.url.searchParams.delete('model');
29
  goto(`?${$page.url.searchParams.toString()}`);
30
  };
31
-
32
- $: console.log(model);
 
 
 
 
 
 
 
33
  </script>
34
 
35
  <div
@@ -51,7 +59,7 @@
51
  <p class="text-white font-semibold text-lg lg:text-2xl mb-1 truncate">
52
  {model?.title ?? model?.id}
53
  </p>
54
- <a href="https://huggingface.co/{model?.id}" target="_blank" class="text-neutral-400 underline hover:text-blue-00 flex items-center justify-start gap-1">
55
  <Icon icon="iconamoon:link-external-fill" class="w-4 h-4" />
56
  View on HuggingFace
57
  </a>
@@ -83,15 +91,23 @@
83
  </a>
84
  </div>
85
  {#if model?.gallery && model?.gallery?.length > 0}
86
- <div>
87
  <p class="text-neutral-400 uppercase text-xs font-bold">Examples</p>
88
- <div class="grid grid-cols-3 md:grid-cols-5 lg:grid-cols-6 gap-5 mt-2">
89
  {#each model?.gallery as example}
90
- <div class="w-full h-[120px] relative z-[1] mb-3 overflow-hidden">
91
  <img src="{env.PUBLIC_FILE_UPLOAD_DIR}/{example.image}" class="w-full h-full bg-center bg-cover rounded-lg object-cover object-center bg-neutral-800" alt={example.prompt} />
92
  </div>
93
  {/each}
94
  </div>
 
 
 
 
 
 
 
 
95
  </div>
96
  {:else}
97
  <div class="bg-neutral-900 rounded-lg p-8 text-center">
 
9
  import UserIsLogged from '$lib/components/UserIsLogged.svelte';
10
  import Comments from '$lib/components/models/drawer/comments/Comments.svelte';
11
  import { env } from '$env/dynamic/public';
12
+ import { browser } from '$app/environment';
13
 
14
  let { open, model } = get(modelStore);
15
 
 
29
  $page.url.searchParams.delete('model');
30
  goto(`?${$page.url.searchParams.toString()}`);
31
  };
32
+
33
+ const handleClickNext = () => {
34
+ // scroll into view
35
+ const element = document.getElementById('gallery_examples');
36
+ element?.scrollBy({
37
+ left: 300,
38
+ behavior: 'smooth'
39
+ });
40
+ }
41
  </script>
42
 
43
  <div
 
59
  <p class="text-white font-semibold text-lg lg:text-2xl mb-1 truncate">
60
  {model?.title ?? model?.id}
61
  </p>
62
+ <a href="https://huggingface.co/{model?.id}" target="_blank" class="text-neutral-400 underline hover:text-neutral-300 flex items-center justify-start gap-1">
63
  <Icon icon="iconamoon:link-external-fill" class="w-4 h-4" />
64
  View on HuggingFace
65
  </a>
 
91
  </a>
92
  </div>
93
  {#if model?.gallery && model?.gallery?.length > 0}
94
+ <div class="-mr-8 relative">
95
  <p class="text-neutral-400 uppercase text-xs font-bold">Examples</p>
96
+ <div id="gallery_examples" class="w-full h-[300px] mt-2 flex flex-nowrap overflow-auto gap-5 relative">
97
  {#each model?.gallery as example}
98
+ <div class="w-[300px] min-w-[300px] h-full relative">
99
  <img src="{env.PUBLIC_FILE_UPLOAD_DIR}/{example.image}" class="w-full h-full bg-center bg-cover rounded-lg object-cover object-center bg-neutral-800" alt={example.prompt} />
100
  </div>
101
  {/each}
102
  </div>
103
+ <div class="w-[100px] h-full absolute right-0 top-0 bg-gradient-to-r from-transparent to-neutral-950 flex items-center justify-end pr-4">
104
+ <button
105
+ class="w-8 h-8 rounded-full bg-neutral-100/20 flex items-center justify-center text-neutral-100 hover:bg-neutral-100/40 transition-all duration-200"
106
+ on:click={handleClickNext}
107
+ >
108
+ <Icon icon="tabler:arrow-narrow-right" class="w-5 h-5" />
109
+ </button>
110
+ </div>
111
  </div>
112
  {:else}
113
  <div class="bg-neutral-900 rounded-lg p-8 text-center">
src/routes/api/models/[id]/+server.ts CHANGED
@@ -29,7 +29,11 @@ export async function GET({ url, params } : RequestEvent) {
29
  },
30
  where: {
31
  isPublic: true
32
- }
 
 
 
 
33
  },
34
  comments: {
35
  select: {
 
29
  },
30
  where: {
31
  isPublic: true
32
+ },
33
+ orderBy: {
34
+ createdAt: 'desc'
35
+ },
36
+ take: 10
37
  },
38
  comments: {
39
  select: {