From 97469f9a3e2c233eae24fdc7b408481d401fe76f Mon Sep 17 00:00:00 2001 From: Xylight Date: Sun, 14 Sep 2025 10:25:55 -0700 Subject: [PATCH] fix: add post flair editing --- .../lemmy/post/actions/PostActions.svelte | 9 +++++++ .../lemmy/post/form/PostForm.svelte | 26 +++++++++---------- src/lib/session.ts | 2 +- .../post/[instance]/[id=integer]/+page.svelte | 1 + 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/lib/components/lemmy/post/actions/PostActions.svelte b/src/lib/components/lemmy/post/actions/PostActions.svelte index b85567f5..c0b34bc3 100644 --- a/src/lib/components/lemmy/post/actions/PostActions.svelte +++ b/src/lib/components/lemmy/post/actions/PostActions.svelte @@ -66,6 +66,15 @@ post = e onedit?.(e) }} + passedData={{ + body: post.post.body, + title: post.post.name, + community: null, + flair_list: post.flair_list?.map((i) => i.id) ?? [], + image: null, + loading: false, + nsfw: post.post.nsfw, + }} > {#snippet formtitle()} diff --git a/src/lib/components/lemmy/post/form/PostForm.svelte b/src/lib/components/lemmy/post/form/PostForm.svelte index e8ba9dc6..5ff21fda 100644 --- a/src/lib/components/lemmy/post/form/PostForm.svelte +++ b/src/lib/components/lemmy/post/form/PostForm.svelte @@ -61,7 +61,7 @@ passedData?: { community: CommunityView | null title: string - body: string + body?: string image: FileList | null thumbnail?: string url?: string @@ -105,6 +105,12 @@ onMount(async () => { if (editingPost) Object.assign(data, editingPost) + if (editingPost?.community_id && !data.community) { + data.community = ( + await client().getCommunity({ id: editingPost.community_id }) + ).community_view + } + if (passedCommunity) { data.community = passedCommunity communitySearch = passedCommunity.community.name @@ -174,14 +180,12 @@ saveDraft = false } - if (data.flair_list.length > 0) { - const piefed = client() - if (piefed.assignFlair) { - await piefed.assignFlair({ - flair_id_list: data.flair_list, - post_id: post.post_view.post.id, - }) - } + const piefed = client() + if (piefed.assignFlair) { + await piefed.assignFlair({ + flair_id_list: data.flair_list, + post_id: post.post_view.post.id, + }) } onsubmit?.(post.post_view) @@ -245,10 +249,6 @@ $effect(() => { generation.generatable = canGenerateTitle(data.url) }) - - $effect(() => { - if (data.community) data.flair_list = [] - }) {#if uploadingImage} diff --git a/src/lib/session.ts b/src/lib/session.ts index 6e803b3c..dd4b8a5a 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -6,7 +6,7 @@ interface SessionStorage { postDraft?: { community: CommunityView | null title: string - body: string + body?: string image: FileList | null url?: string nsfw: boolean diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index 6bdb8b35..55615563 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -85,6 +85,7 @@ color: i.background_color, icon: null, textColor: i.text_color, + type: 'flair' as 'flair' | 'custom', })) ?? []), ], }