From 8129fded763cbd6255133a2af35ea525779f3468 Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 15 Mar 2024 13:16:44 -0700 Subject: [PATCH] fix: recalculate overflow every time post body changes --- src/lib/components/lemmy/post/PostBody.svelte | 14 +++++-- src/lib/components/lemmy/post/PostVote.svelte | 42 ++++++++++--------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/lib/components/lemmy/post/PostBody.svelte b/src/lib/components/lemmy/post/PostBody.svelte index a9a9b177..6a6f7b02 100644 --- a/src/lib/components/lemmy/post/PostBody.svelte +++ b/src/lib/components/lemmy/post/PostBody.svelte @@ -6,16 +6,22 @@ export let body: string export let view: View = 'cozy' - let overflows = false let expanded = false + let element: Element - function isOverflown(element: Element) { - overflows = + function isOverflown(element: Element, body: string = '') { + if (!element) return + let overflows = element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth if (!overflows) expanded = true + else expanded = false + + return overflows } + + $: overflows = isOverflown(element, body)
{#if overflows} diff --git a/src/lib/components/lemmy/post/PostVote.svelte b/src/lib/components/lemmy/post/PostVote.svelte index 19167377..76206983 100644 --- a/src/lib/components/lemmy/post/PostVote.svelte +++ b/src/lib/components/lemmy/post/PostVote.svelte @@ -77,26 +77,28 @@ {/key} -
- + > + + + {#key downvotes} + + + + {/key} + + + {/if}