Spaces:
Running
Running
feat: able to publish even after the generation
Browse files
src/lib/components/community/Card.svelte
CHANGED
|
@@ -7,12 +7,13 @@
|
|
| 7 |
import { galleryStore } from "$lib/stores/use-gallery";
|
| 8 |
import Loading from "$lib/components/Loading.svelte";
|
| 9 |
import Reactions from "./reactions/Reactions.svelte";
|
| 10 |
-
import { success } from "$lib/utils/toaster";
|
| 11 |
|
| 12 |
export let card: CommunityCard;
|
| 13 |
export let form: Record<string, string> | undefined = undefined;
|
| 14 |
export let displayReactions: boolean = true;
|
| 15 |
export let displayDelete: boolean = false;
|
|
|
|
| 16 |
|
| 17 |
let is_visible = true;
|
| 18 |
let loading = false;
|
|
@@ -41,6 +42,17 @@
|
|
| 41 |
if (success) is_visible = false;
|
| 42 |
loading = false;
|
| 43 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
</script>
|
| 45 |
|
| 46 |
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -74,17 +86,35 @@
|
|
| 74 |
{#if displayReactions}
|
| 75 |
<Reactions reactions={card.reactions} gallery_id={card.id} />
|
| 76 |
{/if}
|
| 77 |
-
{#if displayDelete}
|
| 78 |
-
<
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
{/if}
|
| 89 |
{#if loading}
|
| 90 |
<Loading />
|
|
|
|
| 7 |
import { galleryStore } from "$lib/stores/use-gallery";
|
| 8 |
import Loading from "$lib/components/Loading.svelte";
|
| 9 |
import Reactions from "./reactions/Reactions.svelte";
|
| 10 |
+
import { error, success } from "$lib/utils/toaster";
|
| 11 |
|
| 12 |
export let card: CommunityCard;
|
| 13 |
export let form: Record<string, string> | undefined = undefined;
|
| 14 |
export let displayReactions: boolean = true;
|
| 15 |
export let displayDelete: boolean = false;
|
| 16 |
+
export let displayPublish: boolean = false;
|
| 17 |
|
| 18 |
let is_visible = true;
|
| 19 |
let loading = false;
|
|
|
|
| 42 |
if (success) is_visible = false;
|
| 43 |
loading = false;
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
const handlePublish = async (id: string) => {
|
| 47 |
+
if (loading) return;
|
| 48 |
+
loading = true
|
| 49 |
+
const request = await fetch(`/api/community/${id}/publish`, {
|
| 50 |
+
method: "POST"
|
| 51 |
+
});
|
| 52 |
+
const { success } = await request.json();
|
| 53 |
+
if (success) card.isPublic = true;
|
| 54 |
+
loading = false;
|
| 55 |
+
}
|
| 56 |
</script>
|
| 57 |
|
| 58 |
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
|
|
| 86 |
{#if displayReactions}
|
| 87 |
<Reactions reactions={card.reactions} gallery_id={card.id} />
|
| 88 |
{/if}
|
| 89 |
+
{#if displayPublish || displayDelete}
|
| 90 |
+
<div class="absolute bottom-0 left-0 w-full p-4 flex items-center justify-end gap-3">
|
| 91 |
+
{#if displayPublish && !card.isPublic}
|
| 92 |
+
<button
|
| 93 |
+
class="px-4 py-2.5 text-white rounded-full bg-blue-500 backdrop-blur-sm text-sm font-medium transition-all duration-200 hover:bg-blue-700"
|
| 94 |
+
on:click={(e) => {
|
| 95 |
+
e.stopPropagation();
|
| 96 |
+
e.preventDefault();
|
| 97 |
+
handlePublish(card.id);
|
| 98 |
+
success("Published successfully");
|
| 99 |
+
}}
|
| 100 |
+
>
|
| 101 |
+
Publish
|
| 102 |
+
</button>
|
| 103 |
+
{/if}
|
| 104 |
+
{#if displayDelete}
|
| 105 |
+
<button
|
| 106 |
+
class="p-2.5 rounded-full bg-red-500 backdrop-blur-sm transition-all duration-200 hover:bg-red-700"
|
| 107 |
+
on:click={(e) => {
|
| 108 |
+
e.stopPropagation();
|
| 109 |
+
e.preventDefault();
|
| 110 |
+
handleDelete(card.id);
|
| 111 |
+
error("Deleted successfully");
|
| 112 |
+
}}
|
| 113 |
+
>
|
| 114 |
+
<Icon icon="ic:round-delete" class="text-white w-5 h-5" />
|
| 115 |
+
</button>
|
| 116 |
+
{/if}
|
| 117 |
+
</div>
|
| 118 |
{/if}
|
| 119 |
{#if loading}
|
| 120 |
<Loading />
|
src/lib/type.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface CommunityCard {
|
|
| 11 |
model: ModelCard,
|
| 12 |
prompt: string,
|
| 13 |
createdAt: Date,
|
|
|
|
| 14 |
user: UserType,
|
| 15 |
image: string,
|
| 16 |
comments?: CommentType[],
|
|
|
|
| 11 |
model: ModelCard,
|
| 12 |
prompt: string,
|
| 13 |
createdAt: Date,
|
| 14 |
+
isPublic: boolean,
|
| 15 |
user: UserType,
|
| 16 |
image: string,
|
| 17 |
comments?: CommentType[],
|
src/routes/api/@me/generations/+server.ts
CHANGED
|
@@ -35,6 +35,7 @@ export async function GET({ cookies } : RequestEvent) {
|
|
| 35 |
reactions: true,
|
| 36 |
id: true,
|
| 37 |
prompt: true,
|
|
|
|
| 38 |
image: true,
|
| 39 |
model: true,
|
| 40 |
},
|
|
|
|
| 35 |
reactions: true,
|
| 36 |
id: true,
|
| 37 |
prompt: true,
|
| 38 |
+
isPublic: true,
|
| 39 |
image: true,
|
| 40 |
model: true,
|
| 41 |
},
|
src/routes/saved-generations/+page.svelte
CHANGED
|
@@ -17,7 +17,7 @@
|
|
| 17 |
</h1>
|
| 18 |
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
|
| 19 |
{#each data.cards as card}
|
| 20 |
-
<Card card={card} displayReactions={false} displayDelete={true} />
|
| 21 |
{/each}
|
| 22 |
<GoTop />
|
| 23 |
</div>
|
|
|
|
| 17 |
</h1>
|
| 18 |
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
|
| 19 |
{#each data.cards as card}
|
| 20 |
+
<Card card={card} displayReactions={false} displayDelete={true} displayPublish={true} />
|
| 21 |
{/each}
|
| 22 |
<GoTop />
|
| 23 |
</div>
|