File size: 5,615 Bytes
8a18175
 
 
 
 
 
 
 
 
 
 
e1a5fd6
8a18175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c23da5
8a18175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3c7901
 
2c23da5
d3c7901
8a18175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de2d0a9
8a18175
d45617a
de2d0a9
8a18175
 
 
 
 
 
 
 
 
 
 
 
d3c7901
 
8a18175
 
2081a7c
 
 
d3c7901
 
 
 
 
e1a5fd6
d3c7901
 
 
 
 
 
 
 
 
8a18175
 
 
 
 
 
 
 
 
 
 
 
 
 
c8cdf26
8a18175
e88b579
8a18175
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<script lang="ts">
  import { clickoutside } from '@svelte-put/clickoutside';
  import { goto, invalidate } from "$app/navigation";
  import { page } from "$app/stores"; 
  import { get } from "svelte/store";
  import Icon from "@iconify/svelte";

  import { galleryStore } from "$lib/stores/use-gallery";
  import UserIsLogged from '$lib/components/UserIsLogged.svelte';
  import Comments from '$lib/components/community/drawer/Comments.svelte';
  import Reactions from '$lib/components/community/reactions/Reactions.svelte';
  import Image from '$lib/components/models/image/Image.svelte';
  
  export let form: Record<string, string> | undefined = undefined;
  let { open, gallery, next, previous } = get(galleryStore);

  galleryStore.subscribe((value) => {
    open = value?.open;
    gallery = value?.gallery;
    next = value?.next;
    previous = value?.previous;
  });

  const handleClose = async () => {
    galleryStore.update((value) => {
      return {
        ...value,
        open: false,
      };
    });

    await goto(`/gallery`);
    await invalidate(url => url.pathname.includes("/api/models"));
  };
  
  const handleClickNext = () => {
    const element = document.getElementById('gallery_examples');
    element?.scrollBy({
      left: 300,
      behavior: 'smooth'
    });
  }
  const handlePressEscape = (event: KeyboardEvent) => {
    if (event.key === 'Escape') {
      handleClose();
    }
  };
  const handleClickModel = (id?: string) => {
    if (!id) return;
    goto(`/models/${id}`);
  };
</script>

<div
  class="w-full fixed top-0 left-0 h-full bg-black bg-opacity-50 z-0 backdrop-blur transition-all duration-100"
  class:opacity-0={!open}
  class:pointer-events-none={!open}
  class:!z-40={open}
>
  {#if open}
    <div
      class="ml-auto w-full max-w-3xl bg-neutral-950 h-full border-l border-neutral-800 transition-all duration-200 flex flex-col justify-between"
      use:clickoutside on:clickoutside={handleClose}
      >
      {#if gallery?.id}
        <div class="overflow-auto p-8">
          <header class="mb-6 justify-between items-start flex gap-3">
            <div class="flex items-center justify-start gap-4">
              <img src={gallery?.user?.picture?.startsWith('http') ? gallery?.user?.picture : `https://huggingface.co${gallery?.user?.picture}`} class="w-12 h-12 rounded-full object-cover" alt={gallery?.user?.name} />
              <div class="w-full truncate">
                <p class="text-neutral-100 font-bold text-lg">
                  {gallery?.user?.name}
                </p>
                <p class="text-neutral-400 text-sm">
                  @{gallery?.user?.preferred_username}
                </p>
              </div>
            </div>
            <button on:click={handleClose}>
              <Icon icon="carbon:close" class="w-6 h-6 text-white cursor-pointer" />
            </button>
          </header>
          <main class="w-full grid grid-cols-2 gap-5">
            <div class="w-full col-span-2">
              <Reactions reactions={gallery?.reactions} gallery_id={gallery.id} />
            </div>
            <a href="/api/images/{gallery?.image}" target="_blank" class="w-full max-w-[450px] col-span-2">
              <img src="/api/images/{gallery?.image}" class="w-full h-[450px] bg-neutral-800 object-cover rounded-xl" alt={gallery?.prompt} />
            </a>
            <div class="col-span-2">
              <button
                class="flex items-center justify-start gap-4 cursor-pointer w-full text-left transition-all duration-200 hover:bg-neutral-900 p-3 group relative rounded-lg"
                on:click={() => handleClickModel(gallery?.model?.id)}
              >
                <Image src={gallery?.model?.image} generatedImage={gallery?.model?.gallery?.[0]?.image} className="w-14 h-14 rounded-lg object-cover" alt={gallery?.model?.id} />
                <div>
                  <p class="text-neutral-200 text-base font-medium">{gallery?.model?.id}</p>
                  <p class="text-neutral-400 text-sm">{gallery?.model?.id}</p>
                </div>
                <div class="rounded-full absolute top-1/2 -translate-y-1/2 text-neutral-100 w-8 h-8 right-4 bg-pink-500 flex items-center justify-center transition-all duration-200 group-hover:opacity-100 opacity-0">
                  <Icon icon="tabler:arrow-up" class="w-5 h-5 transform rotate-45 font-bold" />
                </div>
              </button>
            </div>
            <div class="px-2">
              <p class="text-neutral-400 font-semibold text-xs uppercase">
                Prompt
              </p>
              <p class="text-neutral-200 text-base font-medium mt-2">"{gallery?.prompt}"</p>
            </div>
            <div class="px-2">
              <p class="text-neutral-400 font-semibold text-xs uppercase">
                Dimension
              </p>
              <p class="text-neutral-200 text-base font-medium mt-2">1024x1024</p>
            </div>
          </main>
        </div>
        <footer class="p-8 border-t border-neutral-900 bg-neutral-900/30 flex flex-col justify-between relative max-h-[80%] overflow-auto">
          <p class="font-semibold text-neutral-100 text-base lg:text-lg mb-6">
            Comment{(gallery?.comments?.length ?? 0) > 1 ? 's' : ''} ({gallery?.comments?.length ?? 0})
          </p>
          {#if gallery?.id}
            <UserIsLogged>
              <Comments comments={gallery?.comments} gallery={gallery} />
            </UserIsLogged>
          {/if}
        </footer>
      {/if}
    </div>
  {/if}
</div>
<svelte:window on:keydown={handlePressEscape} />