enzostvs HF staff commited on
Commit
4530fe2
·
1 Parent(s): 3503213

staff are able to unpublish model

Browse files
src/lib/components/models/Card.svelte CHANGED
@@ -1,14 +1,16 @@
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
 
9
  export let card: ModelCard;
10
 
11
- let visible = true;
12
 
13
  const handleClick = async () => {
14
  $page.url.searchParams.set('model', card?.id);
@@ -32,28 +34,30 @@
32
  });
33
  const response = await request.json();
34
  if (response.success) {
35
- visible = false;
36
- success("Model deleted successfully!");
37
  }
38
  };
39
  </script>
40
 
41
  <!-- svelte-ignore a11y-no-static-element-interactions -->
42
  <!-- svelte-ignore a11y-click-events-have-key-events -->
43
- {#if visible}
44
  <div
45
  class="w-full cursor-pointer group bg-neutral-900 rounded-xl relative flex items-start justify-between flex-col p-3 border border-neutral-800 transition-all duration-200 brightness-90 hover:brightness-100 z-[1]"
46
  on:click={handleClick}
47
  >
48
  <div class="w-full h-[350px] relative z-[1] mb-3 overflow-hidden">
49
  <img src="{card.image}" class="w-full h-full bg-center bg-cover rounded-lg object-cover object-center bg-neutral-800" alt="{card?.id}" />
50
- {#if !card.isPublic}
51
  <div
52
- class="absolute flex items-center justify-between bottom-0 left-0 w-full p-5 bg-neutral-900/30"
53
  on:click={e => e.stopPropagation()}
54
  >
55
- <Button theme="red" onClick={remove}>Delete</Button>
56
- <Button theme="blue" icon="icon-park-solid:check-one" onClick={publish}>Publish</Button>
 
 
 
57
  </div>
58
  {/if}
59
  </div>
@@ -70,5 +74,4 @@
70
  </div>
71
  </div>
72
  </div>
73
- </div>
74
- {/if}
 
1
  <script lang="ts">
2
  import type { ModelCard } from "$lib/type";
3
+ import { get } from "svelte/store";
4
  import Icon from "@iconify/svelte";
5
  import { goto } from "$app/navigation";
6
  import { page } from "$app/stores";
7
  import Button from "$lib/components/Button.svelte";
8
  import { success } from "$lib/utils/toaster";
9
+ import { userStore } from "$lib/stores/use-user";
10
 
11
  export let card: ModelCard;
12
 
13
+ let user = get(userStore);
14
 
15
  const handleClick = async () => {
16
  $page.url.searchParams.set('model', card?.id);
 
34
  });
35
  const response = await request.json();
36
  if (response.success) {
37
+ card.isPublic = false;
38
+ success("Model unpublished successfully!");
39
  }
40
  };
41
  </script>
42
 
43
  <!-- svelte-ignore a11y-no-static-element-interactions -->
44
  <!-- svelte-ignore a11y-click-events-have-key-events -->
 
45
  <div
46
  class="w-full cursor-pointer group bg-neutral-900 rounded-xl relative flex items-start justify-between flex-col p-3 border border-neutral-800 transition-all duration-200 brightness-90 hover:brightness-100 z-[1]"
47
  on:click={handleClick}
48
  >
49
  <div class="w-full h-[350px] relative z-[1] mb-3 overflow-hidden">
50
  <img src="{card.image}" class="w-full h-full bg-center bg-cover rounded-lg object-cover object-center bg-neutral-800" alt="{card?.id}" />
51
+ {#if user?.is_admin}
52
  <div
53
+ class="absolute flex items-center justify-between bottom-0 left-0 w-full p-5 bg-gradient-to-t from-black to-transparent"
54
  on:click={e => e.stopPropagation()}
55
  >
56
+ {#if !card.isPublic}
57
+ <Button theme="blue" icon="icon-park-solid:check-one" onClick={publish}>Publish</Button>
58
+ {:else}
59
+ <Button theme="red" onClick={remove}>Delete</Button>
60
+ {/if}
61
  </div>
62
  {/if}
63
  </div>
 
74
  </div>
75
  </div>
76
  </div>
77
+ </div>
 
src/routes/api/models/[id]/+server.ts CHANGED
@@ -177,9 +177,12 @@ export async function DELETE({ params, cookies } : RequestEvent) {
177
  }, { status: 404 })
178
  }
179
 
180
- await prisma.model.delete({
181
  where: {
182
  id,
 
 
 
183
  }
184
  })
185
 
 
177
  }, { status: 404 })
178
  }
179
 
180
+ await prisma.model.update({
181
  where: {
182
  id,
183
+ },
184
+ data: {
185
+ isPublic: false,
186
  }
187
  })
188