misc: Split post component into more components
This commit is contained in:
1 parent
58057bbeaa
commit
b0f3e01f5a
9 files changed
+183
-188
No files matched your search
@@ -1,5 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { buildCommentsTree } from '$lib/components/lemmy/comment/comments.js'
|
||||
import {
|
||||
buildCommentsTree,
|
||||
buildCommentsTreeAsync,
|
||||
} from '$lib/components/lemmy/comment/comments.js'
|
||||
import Comments from '$lib/components/lemmy/comment/Comments.svelte'
|
||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||
import { isImage } from '$lib/ui/image.js'
|
||||
@@ -14,9 +17,17 @@
|
||||
import { page } from '$app/stores'
|
||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||
import Badge from '$lib/components/ui/Badge.svelte'
|
||||
import { Bookmark, Icon, InformationCircle, Trash } from 'svelte-hero-icons'
|
||||
import {
|
||||
Bookmark,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -51,49 +62,22 @@
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<span class="flex flex-row gap-2 text-sm items-center">
|
||||
<Avatar
|
||||
url={postData.community.icon}
|
||||
width={24}
|
||||
alt={postData.community.name}
|
||||
/>
|
||||
<div class="flex flex-col text-xs">
|
||||
<CommunityLink community={postData.community} />
|
||||
<span class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1">
|
||||
<UserLink user={postData.creator} />
|
||||
<span>•</span>
|
||||
<RelativeDate date={new Date(postData.post.published)} />
|
||||
<span>•</span>
|
||||
<span>
|
||||
{Math.floor(
|
||||
(data.post.post_view.counts.upvotes /
|
||||
(data.post.post_view.counts.upvotes +
|
||||
data.post.post_view.counts.downvotes || 1)) *
|
||||
100
|
||||
)}%
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
{#if $authData && $page.params.instance != $authData.instance}
|
||||
<Card cardColor="warning" class="p-4 flex flex-col gap-1">
|
||||
<Icon
|
||||
src={ExclamationTriangle}
|
||||
width={24}
|
||||
solid
|
||||
class="text-yellow-500"
|
||||
/>
|
||||
<h1 class="font-bold">Warning</h1>
|
||||
<p class="text-sm">
|
||||
This URL is for a different instance than you're logged into. You
|
||||
probably won't be able to vote or comment.
|
||||
</p>
|
||||
</Card>
|
||||
{/if}
|
||||
|
||||
{#if data.post.post_view.post.nsfw}
|
||||
<Badge class="bg-red-600 text-white">NSFW</Badge>
|
||||
{/if}
|
||||
{#if data.post.post_view.saved}
|
||||
<Badge class="bg-yellow-500 text-white py-1" label="Saved">
|
||||
<Icon src={Bookmark} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if data.post.post_view.post.deleted || data.post.post_view.post.removed}
|
||||
<Badge class="bg-red-600 text-white py-1" label="Deleted">
|
||||
<Icon src={Trash} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if data.post.post_view.post.featured_community || data.post.post_view.post.featured_local}
|
||||
<Badge class="bg-green-500 text-white py-1" label="Pinned">
|
||||
<Icon src={InformationCircle} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
</span>
|
||||
<h1 class="font-bold text-lg">{post.name}</h1>
|
||||
{#if isImage(post.url)}
|
||||
<img
|
||||
@@ -102,25 +86,11 @@
|
||||
class="rounded-md max-w-screen max-h-[80vh] mx-auto"
|
||||
/>
|
||||
{:else if post.thumbnail_url && post.url}
|
||||
<a
|
||||
href={post.url}
|
||||
class="self-start relative group"
|
||||
class:blur-3xl={post.nsfw}
|
||||
>
|
||||
<img
|
||||
src={post.thumbnail_url}
|
||||
alt={post.name}
|
||||
class="rounded-md max-h-[16rem] w-full max-w-full"
|
||||
/>
|
||||
<span
|
||||
class="w-full px-4 py-2 overflow-hidden
|
||||
whitespace-nowrap text-ellipsis text-sm group-hover:underline bg-slate-100 dark:bg-zinc-800 border dark:border-transparent
|
||||
absolute bottom-0 rounded-b-md flex flex-row gap-1 items-center h-10"
|
||||
>
|
||||
<Icon src={Link} width={16} mini />
|
||||
{new URL(post.url).hostname}
|
||||
</span>
|
||||
</a>
|
||||
<PostLink
|
||||
thumbnail_url={post.thumbnail_url}
|
||||
url={post.url}
|
||||
nsfw={post.nsfw}
|
||||
/>
|
||||
{:else if post.embed_video_url}
|
||||
<!-- svelte-ignore a11y-media-has-caption -->
|
||||
<video class="rounded-md max-w-screen max-h-[80vh] mx-auto">
|
||||
@@ -160,11 +130,13 @@
|
||||
])}
|
||||
/>
|
||||
{/if}
|
||||
<Comments
|
||||
{post}
|
||||
nodes={buildCommentsTree(comments.comments, false)}
|
||||
isParent={true}
|
||||
/>
|
||||
{#await buildCommentsTreeAsync(comments.comments, false)}
|
||||
<div class="h-16 mx-auto grid place-items-center">
|
||||
<Spinner width={36} />
|
||||
</div>
|
||||
{:then comments}
|
||||
<Comments {post} nodes={comments} isParent={true} />
|
||||
{/await}
|
||||
{#if moreComments}
|
||||
<Button
|
||||
{loading}
|
||||
|
||||
Reference in new issue
Block a user