fix: recalculate overflow every time post body changes

This commit is contained in:
Xylight committed 2024-03-15 14:34:51 -07:00
1 parent 6c0dfdca01
commit 8129fded76
2 files changed
+32 -24

No files matched your search

+10 -4
View File
@@ -6,16 +6,22 @@
export let body: string export let body: string
export let view: View = 'cozy' export let view: View = 'cozy'
let overflows = false
let expanded = false let expanded = false
let element: Element
function isOverflown(element: Element) { function isOverflown(element: Element, body: string = '') {
overflows = if (!element) return
let overflows =
element.scrollHeight > element.clientHeight || element.scrollHeight > element.clientHeight ||
element.scrollWidth > element.clientWidth element.scrollWidth > element.clientWidth
if (!overflows) expanded = true if (!overflows) expanded = true
else expanded = false
return overflows
} }
$: overflows = isOverflown(element, body)
</script> </script>
<div <div
@@ -26,7 +32,7 @@ bg-gradient-to-b text-transparent from-slate-600 via-slate-600
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0
${view == 'list' ? `max-h-24` : 'max-h-48'}` ${view == 'list' ? `max-h-24` : 'max-h-48'}`
: 'text-slate-600 dark:text-zinc-400 max-h-full'} {$$props.class ?? ''}" : 'text-slate-600 dark:text-zinc-400 max-h-full'} {$$props.class ?? ''}"
use:isOverflown bind:this={element}
> >
<Markdown inline={!expanded} source={body} /> <Markdown inline={!expanded} source={body} />
{#if overflows} {#if overflows}
+22 -20
View File
@@ -77,26 +77,28 @@
{/key} {/key}
</span> </span>
</button> </button>
<div {#if $site?.site_view.local_site.enable_downvotes ?? true}
class="border-l h-6 w-0 !p-0 border-slate-200 dark:border-zinc-800" <div
></div> class="border-l h-6 w-0 !p-0 border-slate-200 dark:border-zinc-800"
<button ></div>
on:click={() => castVote(vote == -1 ? 0 : -1)} <button
class="flex items-center gap-0.5 !pr-2.5 {buttonColor.secondary} transition-colors border-0 on:click={() => castVote(vote == -1 ? 0 : -1)}
class="flex items-center gap-0.5 !pr-2.5 {buttonColor.secondary} transition-colors border-0
{vote == -1 ? shouldShowVoteColor(vote, 'downvotes') : ''}" {vote == -1 ? shouldShowVoteColor(vote, 'downvotes') : ''}"
> >
<Icon src={ChevronDown} size="18" mini /> <Icon src={ChevronDown} size="18" mini />
<span class="grid text-sm"> <span class="grid text-sm">
{#key downvotes} {#key downvotes}
<span <span
style="grid-column: 1; grid-row: 1;" style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 200, y: -6 }} in:fly={{ duration: 200, y: -6 }}
out:fly={{ duration: 200, y: 6 }} out:fly={{ duration: 200, y: 6 }}
> >
<FormattedNumber number={downvotes} /> <FormattedNumber number={downvotes} />
</span> </span>
{/key} {/key}
</span> </span>
</button> </button>
{/if}
</div> </div>
</slot> </slot>