feat: change compact post style

This commit is contained in:
Xyphyn committed 2023-08-31 18:38:41 -07:00
1 parent 4ba2235c01
commit 9833a775c4
3 files changed
+145 -125

No files matched your search

+109 -96
View File
@@ -14,35 +14,108 @@
export let post: PostView export let post: PostView
export let actions: boolean = true export let actions: boolean = true
export let hideCommunity = false export let hideCommunity = false
export let compact: boolean = false
let loaded = false let loaded = false
</script> </script>
<Card class="bg-white flex flex-col w-full p-5 gap-2.5" id={post.post.id}> <Card
<div class="flex flex-row w-full gap-2.5"> class="flex flex-col w-full gap-2.5 {compact
<div class="flex flex-col gap-1.5 grow"> ? '!bg-transparent !border-0 py-5'
<PostMeta : 'p-5'}"
community={hideCommunity ? undefined : post.community} id={post.post.id}
user={post.creator} >
published={new Date(post.post.published + 'Z')} <div class="flex flex-row gap-2 w-full">
upvotes={post.counts.upvotes} <div class="flex flex-col gap-2 w-full">
downvotes={post.counts.downvotes} <div class="flex flex-col w-full gap-2">
deleted={post.post.deleted} <PostMeta
removed={post.post.removed} community={hideCommunity ? undefined : post.community}
locked={post.post.locked} user={post.creator}
featured={post.post.featured_local || post.post.featured_community} published={new Date(post.post.published + 'Z')}
nsfw={post.post.nsfw} upvotes={post.counts.upvotes}
saved={post.saved} downvotes={post.counts.downvotes}
/> deleted={post.post.deleted}
<a removed={post.post.removed}
href="/post/{getInstance()}/{post.post.id}" locked={post.post.locked}
class="font-medium max-w-full w-full break-words" featured={post.post.featured_local || post.post.featured_community}
style="word-break: break-word;" nsfw={post.post.nsfw}
class:text-slate-500={post.read && $userSettings.markReadPosts} saved={post.saved}
class:dark:text-zinc-400={post.read && $userSettings.markReadPosts} />
> <a
{post.post.name} href="/post/{getInstance()}/{post.post.id}"
</a> class="font-medium max-w-full w-full break-words"
style="word-break: break-word;"
class:text-slate-500={post.read && $userSettings.markReadPosts}
class:dark:text-zinc-400={post.read && $userSettings.markReadPosts}
>
{post.post.name}
</a>
</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)}
<!--disabled preloads here since most people will hover over every image while scrolling-->
<a
href="/post/{getInstance()}/{post.post.id}"
class="self-start overflow-hidden z-10 relative bg-slate-200 dark:bg-zinc-800 rounded-md max-w-full"
data-sveltekit-preload-data="off"
aria-label={post.post.name}
>
<picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
>
<source
srcset="{post.post.url}?thumbnail=256&format=webp"
media="(max-width: 256px)"
/>
<source
srcset="{post.post.url}?thumbnail=512&format=webp"
media="(max-width: 512px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=512&format=webp"
loading="lazy"
class="max-w-full object-cover rounded-md max-h-[80vh] h-auto z-30 opacity-0 transition-opacity duration-300"
class:opacity-100={loaded}
width={512}
height={300}
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
on:load={() => (loaded = true)}
/>
</picture>
</a>
{:else if post.post.thumbnail_url && post.post.url}
<PostLink
url={post.post.url}
thumbnail_url="{post.post.thumbnail_url}?format=webp&thumbnail=512"
nsfw={post.post.nsfw}
/>
{/if}
{/if}
{#if post.post.body && !post.post.nsfw}
<div
class="text-sm relative overflow-hidden {compact
? `text-zinc-500 max-h-24`
: 'text-slate-600 max-h-48'}"
>
<Markdown inline source={post.post.body.slice(0, 400)} />
{#if post.post.body.length > (compact ? 300 : 600)}
<div
class="absolute bottom-0 w-full h-16 bg-gradient-to-b {compact
? 'dark:from-zinc-950/0 dark:to-zinc-950 from-slate-50/0 to-slate-50'
: 'dark:from-zinc-900/0 dark:to-zinc-900 from-white/0 to-white'} "
/>
{/if}
</div>
{/if}
</div> </div>
{#if $userSettings.showCompactPosts && (post.post.thumbnail_url || isImage(post.post.url))} {#if $userSettings.showCompactPosts && (post.post.thumbnail_url || isImage(post.post.url))}
<div class="flex-none w-24 h-24"> <div class="flex-none w-24 h-24">
@@ -66,77 +139,17 @@
</div> </div>
{/if} {/if}
</div> </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)}
<!--disabled preloads here since most people will hover over every image while scrolling-->
<a
href="/post/{getInstance()}/{post.post.id}"
class="self-start overflow-hidden z-10 relative bg-slate-200 dark:bg-zinc-800 rounded-md max-w-full"
data-sveltekit-preload-data="off"
aria-label={post.post.name}
>
<picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
>
<source
srcset="{post.post.url}?thumbnail=256&format=webp"
media="(max-width: 256px)"
/>
<source
srcset="{post.post.url}?thumbnail=512&format=webp"
media="(max-width: 512px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=512&format=webp"
loading="lazy"
class="max-w-full object-cover rounded-md max-h-[80vh] h-auto z-30 opacity-0 transition-opacity duration-300"
class:opacity-100={loaded}
width={512}
height={300}
class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
on:load={() => (loaded = true)}
/>
</picture>
</a>
{:else if post.post.thumbnail_url && post.post.url}
<PostLink
url={post.post.url}
thumbnail_url="{post.post.thumbnail_url}?format=webp&thumbnail=512"
nsfw={post.post.nsfw}
/>
{/if}
{#if post.post.body && !post.post.nsfw}
<div
class="text-sm bg-slate-100 dark:bg-zinc-800
border border-slate-200 dark:border-zinc-700 rounded-md p-2"
>
<Markdown
inline
source={post.post.body.length > 350
? `${post.post.body.slice(0, 350)}...`
: post.post.body}
/>
</div>
{/if}
{/if}
{#if actions} {#if actions}
<PostActions <div class="w-full z-30" class:mt-2={compact}>
bind:post <PostActions
on:edit={(e) => { bind:post
toast({ on:edit={(e) => {
content: 'The post was edited successfully.', toast({
type: 'success', content: 'The post was edited successfully.',
}) type: 'success',
}} })
/> }}
/>
</div>
{/if} {/if}
</Card> </Card>
+35 -28
View File
@@ -10,32 +10,39 @@
export let posts: PostView[] export let posts: PostView[]
</script> </script>
{#if posts.length == 0} <div
<div class="h-full grid place-items-center"> class="flex flex-col {!$userSettings.showCompactPosts
<Placeholder ? 'gap-3 md:gap-4'
icon={ArchiveBox} : ''} divide-slate-200 dark:divide-zinc-800"
title="No posts" class:divide-y={$userSettings.showCompactPosts}
description="There are no posts that match this filter." >
> {#if posts.length == 0}
<Button href="/communities"> <div class="h-full grid place-items-center">
<Icon src={Plus} size="16" mini slot="icon" /> <Placeholder
<span>Follow some communities</span> icon={ArchiveBox}
</Button> title="No posts"
</Placeholder> description="There are no posts that match this filter."
</div>
{:else}
{#each posts as post, index (post.post.id)}
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
<div
in:fly={{
y: -8,
duration: 500,
opacity: 0,
delay: index < 4 ? index * 100 : 0,
}}
> >
<Post {post} /> <Button href="/communities">
</div> <Icon src={Plus} size="16" mini slot="icon" />
{/if} <span>Follow some communities</span>
{/each} </Button>
{/if} </Placeholder>
</div>
{:else}
{#each posts as post, index (post.post.id)}
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
<div
in:fly={{
y: -8,
duration: 500,
opacity: 0,
delay: index < 4 ? index * 100 : 0,
}}
>
<Post compact={$userSettings.showCompactPosts} {post} />
</div>
{/if}
{/each}
{/if}
</div>
+1 -1
View File
@@ -30,7 +30,7 @@ export const md = new MarkdownIt({
.use(markdown_it_sup) .use(markdown_it_sup)
export const mdInline: MarkdownIt = new MarkdownIt('zero') export const mdInline: MarkdownIt = new MarkdownIt('zero')
.enable(['emphasis', 'backticks', 'strikethrough', 'link']) .enable(['emphasis', 'backticks', 'strikethrough', 'link', 'list', 'heading'])
.use(markdown_it_container, 'spoiler', { .use(markdown_it_container, 'spoiler', {
validate: (params: string) => { validate: (params: string) => {
return params.trim().match(/^spoiler+(.*)/) return params.trim().match(/^spoiler+(.*)/)