misc: Minor design tweaks
This commit is contained in:
1 parent
3bb849cb4b
commit
9d21f6331a
14 files changed
+25
-26
No files matched your search
@@ -0,0 +1,149 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||
import { isImage } from '$lib/ui/image.js'
|
||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||
import Badge from '$lib/components/ui/Badge.svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
HandThumbDown,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
Link,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
|
||||
let postRes: PostView
|
||||
export { postRes as post }
|
||||
</script>
|
||||
|
||||
<Card class="bg-white flex flex-col w-full p-5 gap-2.5">
|
||||
<span class="flex flex-row gap-2 text-xs items-center">
|
||||
<Avatar
|
||||
url={postRes.community.icon}
|
||||
alt={postRes.community.title}
|
||||
width={24}
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<CommunityLink community={postRes.community} />
|
||||
<span class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1">
|
||||
<UserLink user={postRes.creator} />
|
||||
<span>•</span>
|
||||
<RelativeDate date={new Date(postRes.post.published)} />
|
||||
<span>•</span>
|
||||
<span>
|
||||
{Math.floor(
|
||||
(postRes.counts.upvotes /
|
||||
(postRes.counts.upvotes + postRes.counts.downvotes || 1)) *
|
||||
100
|
||||
)}%
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<!-- Badges -->
|
||||
<div class="flex flex-row ml-auto gap-2">
|
||||
{#if postRes.post.nsfw}
|
||||
<Badge class="bg-red-600 text-white">NSFW</Badge>
|
||||
{/if}
|
||||
{#if postRes.counts.score < 0 && postRes.counts.upvotes > 3 && postRes.counts.downvotes > 3}
|
||||
<Badge class="bg-purple-400 text-white py-1" label="Controversial">
|
||||
<Icon src={HandThumbDown} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if postRes.saved}
|
||||
<Badge class="bg-yellow-500 text-white py-1" label="Saved">
|
||||
<Icon src={Bookmark} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if postRes.post.deleted || postRes.post.removed}
|
||||
<Badge class="bg-red-600 text-white py-1" label="Deleted">
|
||||
<Icon src={Trash} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if postRes.post.featured_community || postRes.post.featured_local}
|
||||
<Badge class="bg-green-500 text-white py-1" label="Pinned">
|
||||
<Icon src={InformationCircle} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
</span>
|
||||
<a
|
||||
href="/post/{getInstance()}/{postRes.post.id}"
|
||||
class="font-bold"
|
||||
class:opacity-50={postRes.read && $userSettings.markReadPosts}
|
||||
>
|
||||
{postRes.post.name}
|
||||
</a>
|
||||
{#if postRes.post.url && !postRes.post.thumbnail_url}
|
||||
<a
|
||||
href={postRes.post.url}
|
||||
class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs"
|
||||
>
|
||||
{postRes.post.url}
|
||||
</a>
|
||||
{/if}
|
||||
{#if isImage(postRes.post.url)}
|
||||
<div class="self-start" class:blur-3xl={postRes.post.nsfw}>
|
||||
<picture
|
||||
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
|
||||
>
|
||||
<source
|
||||
srcset="{postRes.post.url}?thumbnail=256&format=webp"
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset="{postRes.post.url}?thumbnail=512&format=webp"
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<source
|
||||
srcset="{postRes.post.url}?thumbnail=720&format=webp"
|
||||
media="(max-width: 720px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src="{postRes.post.url}?thumbnail=1024&format=webp"
|
||||
loading="lazy"
|
||||
class="object-cover bg-slate-100 rounded-md max-h-[50vh] w-full"
|
||||
width={512}
|
||||
height={300}
|
||||
/>
|
||||
</picture>
|
||||
</div>
|
||||
{:else if postRes.post.thumbnail_url && postRes.post.url}
|
||||
<a
|
||||
href={postRes.post.url}
|
||||
class="self-start relative group"
|
||||
class:blur-3xl={postRes.post.nsfw}
|
||||
>
|
||||
<img
|
||||
src={postRes.post.thumbnail_url}
|
||||
alt={postRes.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 border
|
||||
dark:border-zinc-700
|
||||
dark:bg-zinc-800 absolute bottom-0 rounded-b-md flex flex-row gap-1 items-center"
|
||||
>
|
||||
<Icon src={Link} width={16} mini />
|
||||
{new URL(postRes.post.url).hostname}
|
||||
</span>
|
||||
</a>
|
||||
{/if}
|
||||
{#if postRes.post.body && !postRes.post.nsfw}
|
||||
<p
|
||||
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"
|
||||
>
|
||||
{postRes.post.body}
|
||||
</p>
|
||||
{/if}
|
||||
<PostActions post={postRes} />
|
||||
</Card>
|
||||
@@ -0,0 +1,114 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import PostVote from './PostVote.svelte'
|
||||
import { getClient, getInstance } from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
BookmarkSlash,
|
||||
ChatBubbleOvalLeft,
|
||||
EllipsisHorizontal,
|
||||
Icon,
|
||||
Newspaper,
|
||||
Square2Stack,
|
||||
Trash,
|
||||
UserCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||
import { page } from '$app/stores'
|
||||
import { user, authData } from '$lib/lemmy.js'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
|
||||
export let post: PostView
|
||||
|
||||
async function deletePost() {
|
||||
if (!$authData) return
|
||||
|
||||
await getClient().deletePost({
|
||||
auth: $authData.token,
|
||||
deleted: true,
|
||||
post_id: post.post.id,
|
||||
})
|
||||
}
|
||||
|
||||
async function save(post: PostView) {
|
||||
if (!$authData) return
|
||||
|
||||
const saved = post.saved
|
||||
|
||||
post.saved = !saved
|
||||
|
||||
try {
|
||||
await getClient().savePost({
|
||||
auth: $authData.token,
|
||||
post_id: post.post.id,
|
||||
save: !saved,
|
||||
})
|
||||
} catch (error) {
|
||||
post.saved = saved
|
||||
|
||||
toast({
|
||||
content: error as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<PostVote post={post.post} vote={post.my_vote} score={post.counts.score} />
|
||||
|
||||
<Link color={Color.border} href="/post/{getInstance()}/{post.post.id}">
|
||||
<Icon slot="icon" src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Link>
|
||||
<Menu alignment="bottom-right" class="ml-auto overflow-auto" let:toggleOpen>
|
||||
<Button slot="button" label="Post actions" on:click={toggleOpen}>
|
||||
<Icon src={EllipsisHorizontal} width={16} mini />
|
||||
</Button>
|
||||
<li class="mx-4 text-xs opacity-80 text-left my-1 py-1">Creator</li>
|
||||
<MenuButton
|
||||
link
|
||||
href="/u/{post.creator.name}@{new URL(post.creator.actor_id).hostname}"
|
||||
>
|
||||
<Icon src={UserCircle} width={16} mini />
|
||||
<span>{post.creator.name}</span>
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
link
|
||||
href="/c/{post.community.name}@{new URL(post.community.actor_id)
|
||||
.hostname}"
|
||||
>
|
||||
<Icon src={Newspaper} width={16} mini />
|
||||
<span>{post.community.title}</span>
|
||||
</MenuButton>
|
||||
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
|
||||
<li class="mx-4 text-xs opacity-80 text-left my-1 py-1">Actions</li>
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
navigator.clipboard.writeText(
|
||||
`${$page.url.origin}/post/${getInstance()}/${post.post.id}`
|
||||
)
|
||||
}}
|
||||
>
|
||||
<Icon src={Square2Stack} width={16} mini />
|
||||
Copy Link
|
||||
</MenuButton>
|
||||
{#if $authData?.token}
|
||||
<MenuButton on:click={() => save(post)}>
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
|
||||
{post.saved ? 'Unsave' : 'Save'}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $user?.person.id == post.post.creator_id}
|
||||
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
||||
<Icon src={Trash} width={16} mini />
|
||||
Delete
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
</div>
|
||||
@@ -0,0 +1,93 @@
|
||||
<script lang="ts">
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { authData, getClient } from '$lib/lemmy'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let post: Post
|
||||
export let vote: number = 0
|
||||
export let score: number
|
||||
|
||||
async function upvote() {
|
||||
if (!$authData) return
|
||||
|
||||
if (vote == undefined) vote = 0
|
||||
|
||||
const upvoted = vote == 1
|
||||
|
||||
if (vote == -1) {
|
||||
score += 2
|
||||
} else if (vote == 1) {
|
||||
score -= 1
|
||||
} else if (vote == 0) {
|
||||
score += 1
|
||||
}
|
||||
|
||||
vote = Number(!upvoted)
|
||||
|
||||
await getClient()
|
||||
.likePost({
|
||||
score: upvoted ? 0 : 1,
|
||||
auth: $authData.token,
|
||||
post_id: post.id,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
|
||||
async function downvote() {
|
||||
if (!$authData) return
|
||||
|
||||
if (vote == undefined) vote = 0
|
||||
|
||||
const upvoted = vote == -1
|
||||
|
||||
if (vote == -1) {
|
||||
score += 1
|
||||
} else if (vote == 1) {
|
||||
score -= 2
|
||||
} else if (vote == 0) {
|
||||
score -= 1
|
||||
}
|
||||
|
||||
vote = -Number(!upvoted)
|
||||
|
||||
await getClient()
|
||||
.likePost({
|
||||
score: upvoted ? 0 : -1,
|
||||
auth: $authData.token,
|
||||
post_id: post.id,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot {upvote} {downvote} {vote} {score}>
|
||||
<div
|
||||
class="{Color.border} text-sm gap-0.5 rounded-md flex flex-row items-center px-1
|
||||
py-0.5
|
||||
transition-colors cursor-pointer bg-slate-100 dark:bg-zinc-800
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700"
|
||||
>
|
||||
<button
|
||||
aria-label="Upvote"
|
||||
class:text-orange-500={vote == 1 && $userSettings.revertColors}
|
||||
class:text-blue-500={vote == 1 && !$userSettings.revertColors}
|
||||
class="p-0.5 px-1"
|
||||
on:click={upvote}
|
||||
>
|
||||
<Icon src={ChevronUp} mini width={20} height={20} />
|
||||
</button>
|
||||
<FormattedNumber number={score} />
|
||||
<button
|
||||
aria-label="Downvote"
|
||||
class:text-blue-500={vote == -1 && $userSettings.revertColors}
|
||||
class:text-red-500={vote == -1 && !$userSettings.revertColors}
|
||||
class="p-0.5 px-1"
|
||||
on:click={downvote}
|
||||
>
|
||||
<Icon src={ChevronDown} mini width={20} height={20} />
|
||||
</button>
|
||||
</div>
|
||||
</slot>
|
||||
Reference in new issue
Block a user