feat: show compact posts (#22)

Add a new UI setting for showing compact posts:

- Show a small thumbnail to the right of the metadata and title if a
  thumbnail is available or if the post is an image
- Do not show normal thumbnail or text bodies.
This commit is contained in:
Peter Bui authored and GitHub committed 2023-07-26 10:32:04 -07:00
1 parent d696e2ee00
commit e028113ab0
3 files changed
+79 -43

No files matched your search

+72 -43
View File
@@ -15,34 +15,62 @@
</script> </script>
<Card class="bg-white flex flex-col w-full p-5 gap-2.5"> <Card class="bg-white flex flex-col w-full p-5 gap-2.5">
<PostMeta <div class="flex flex-row w-full gap-2.5">
community={post.community} <div class="flex flex-col gap-2.5 grow">
user={post.creator} <PostMeta
published={new Date(post.post.published)} community={post.community}
upvotes={post.counts.upvotes} user={post.creator}
downvotes={post.counts.downvotes} published={new Date(post.post.published)}
deleted={post.post.deleted} upvotes={post.counts.upvotes}
featured={post.post.featured_local || post.post.featured_community} downvotes={post.counts.downvotes}
nsfw={post.post.nsfw} deleted={post.post.deleted}
saved={post.saved} featured={post.post.featured_local || post.post.featured_community}
/> nsfw={post.post.nsfw}
<a saved={post.saved}
href="/post/{getInstance()}/{post.post.id}" />
class="font-bold" <a
class:opacity-50={post.read && $userSettings.markReadPosts} href="/post/{getInstance()}/{post.post.id}"
> class="font-bold"
{post.post.name} class:opacity-50={post.read && $userSettings.markReadPosts}
</a> >
{#if post.post.url && !post.post.thumbnail_url} {post.post.name}
<a </a>
href={post.post.url} </div>
class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs" {#if $userSettings.showCompactPosts && (post.post.thumbnail_url || isImage(post.post.url))}
> <div class="flex-none w-24 h-24">
{post.post.url} <a
</a> href="/post/{getInstance()}/{post.post.id}"
{/if} >
{#if isImage(post.post.url)} {#if post.post.thumbnail_url}
<div class="self-start" class:blur-3xl={post.post.nsfw}> <!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.thumbnail_url}?thumbnail=256&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{:else}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=256&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{/if}
</a>
</div>
{/if}
</div>
{#if !$userSettings.showCompactPosts}
{#if post.post.url && !post.post.thumbnail_url}
<a
href={post.post.url}
class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs"
>
{post.post.url}
</a>
{/if}
{#if isImage(post.post.url)}
<div class="self-start" class:blur-3xl={post.post.nsfw}>
<picture <picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full" class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
> >
@@ -67,21 +95,22 @@
height={300} height={300}
/> />
</picture> </picture>
</div> </div>
{:else if post.post.thumbnail_url && post.post.url} {:else if post.post.thumbnail_url && post.post.url}
<PostLink <PostLink
url={post.post.url} url={post.post.url}
thumbnail_url={post.post.thumbnail_url} thumbnail_url={post.post.thumbnail_url}
nsfw={post.post.nsfw} nsfw={post.post.nsfw}
/> />
{/if} {/if}
{#if post.post.body && !post.post.nsfw} {#if post.post.body && !post.post.nsfw}
<p <p
class="text-sm max-h-[74px] line-clamp-3 bg-slate-100 dark:bg-zinc-800 class="text-sm max-h-[74px] line-clamp-3 bg-slate-100 dark:bg-zinc-800
border border-slate-200 dark:border-zinc-700 rounded-md p-2" border border-slate-200 dark:border-zinc-700 rounded-md p-2"
> >
{post.post.body} {post.post.body}
</p> </p>
{/if}
{/if} {/if}
<PostActions <PostActions
{post} {post}
+2
View File
@@ -7,6 +7,7 @@ interface Settings {
instance?: string instance?: string
revertColors: boolean revertColors: boolean
showInstance: boolean showInstance: boolean
showCompactPosts: boolean
defaultSort: { defaultSort: {
sort: 'Hot' | 'TopAll' | 'Active' | 'New' sort: 'Hot' | 'TopAll' | 'Active' | 'New'
feed: 'All' | 'Subscribed' | 'Local' feed: 'All' | 'Subscribed' | 'Local'
@@ -19,6 +20,7 @@ const defaultSettings: Settings = {
markReadPosts: true, markReadPosts: true,
revertColors: false, revertColors: false,
showInstance: false, showInstance: false,
showCompactPosts: false,
defaultSort: { defaultSort: {
sort: 'Active', sort: 'Active',
feed: 'Local', feed: 'Local',
+5
View File
@@ -114,4 +114,9 @@
</span> </span>
<Switch bind:enabled={$userSettings.showInstance} /> <Switch bind:enabled={$userSettings.showInstance} />
</Setting> </Setting>
<Setting>
<span slot="title">Show compact posts</span>
<span slot="description">Show posts with smaller thumbnails and without text bodies.</span>
<Switch bind:enabled={$userSettings.showCompactPosts} />
</Setting>
</div> </div>