feat: Add upvote %

This commit is contained in:
Xyphyn committed 2023-07-06 13:28:38 -07:00
1 parent 71ca33d9fc
commit 54b1cef68f
3 files changed
+120 -98

No files matched your search

+8
View File
@@ -61,6 +61,14 @@
<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>
<div class="ml-auto" />
+2 -2
View File
@@ -1,8 +1,8 @@
<div
class="sticky top-20 border bg-white shadow-md border-slate-100
dark:border-zinc-800 dark:bg-zinc-900 break-words hidden lg:flex
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-6rem)]
overflow-auto w-full"
flex-col gap-4 p-8 max-w-[20rem] min-w-[20rem] rounded-md h-max max-h-[calc(100vh-6rem)]
overflow-auto"
>
<slot />
</div>
+110 -96
View File
@@ -101,103 +101,117 @@
<title>{data.post.post_view.post.name}</title>
</svelte:head>
<div class="flex flex-col gap-2">
<span class="flex flex-row gap-2 text-sm opacity-80 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="opacity-50 flex flex-row gap-1">
<UserLink user={postData.creator} />
<span>•</span>
<RelativeDate date={new Date(postData.post.published)} />
</span>
</div>
</span>
<h1 class="font-bold text-lg">{post.name}</h1>
{#if post.url}
<a
href={post.url}
class="text-sky-400 max-w-[48ch] overflow-hidden
whitespace-nowrap text-ellipsis text-xs hover:underline"
>
{post.url}
</a>
{/if}
{#if isImage(post.url)}
<img
src={post.url}
alt={post.name}
class="rounded-md max-w-screen max-h-[80vh] mx-auto"
/>
{:else if isVideo(post.url)}
<!-- svelte-ignore a11y-media-has-caption -->
<video class="rounded-md max-w-screen max-h-[80vh] mx-auto">
<source src={post.url} />
</video>
{/if}
{#if post.body}
<p
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
dark:bg-zinc-900 p-2 text-sm rounded-md leading-5"
>
<Markdown source={post.body} />
</p>
{/if}
<div class="w-max">
<PostVote
post={data.post.post_view.post}
score={data.post.post_view.counts.score}
vote={data.post.post_view.my_vote}
/>
</div>
</div>
<div class="mt-4 flex flex-col gap-2">
<div class="font-bold text-lg">
Comments <span class="text-sm font-normal ml-2 opacity-80">
{postData.counts.comments}
</span>
</div>
{#await data.streamed.comments}
<div class="flex flex-col gap-8">
{#each new Array(10) as comment}
<div class="flex flex-col gap-2">
<div
class="dark:bg-zinc-700 bg-slate-200 animate-pulse w-64 h-3 rounded-md"
/>
<div
class="dark:bg-zinc-700 bg-slate-200 animate-pulse w-128 h-4 rounded-md"
/>
<div class="flex flex-row gap-4">
<div>
<div class="flex flex-col gap-2">
<span class="flex flex-row gap-2 text-sm opacity-80 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="opacity-50 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>
{/each}
</span>
<h1 class="font-bold text-lg">{post.name}</h1>
{#if post.url}
<a
href={post.url}
class="text-sky-400 max-w-[48ch] overflow-hidden
whitespace-nowrap text-ellipsis text-xs hover:underline"
>
{post.url}
</a>
{/if}
{#if isImage(post.url)}
<img
src={post.url}
alt={post.name}
class="rounded-md max-w-screen max-h-[80vh] mx-auto"
/>
{:else if isVideo(post.url)}
<!-- svelte-ignore a11y-media-has-caption -->
<video class="rounded-md max-w-screen max-h-[80vh] mx-auto">
<source src={post.url} />
</video>
{/if}
{#if post.body}
<p
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
dark:bg-zinc-900 p-2 text-sm rounded-md leading-5"
>
<Markdown source={post.body} />
</p>
{/if}
<div class="w-max">
<PostVote
post={data.post.post_view.post}
score={data.post.post_view.counts.score}
vote={data.post.post_view.my_vote}
/>
</div>
</div>
{:then comments}
{#if $user}
<CommentForm
postId={post.id}
on:comment={(comment) =>
(comments.comments = [
comment.detail.comment_view,
...comments.comments,
])}
/>
{/if}
<MultiSelect
options={['hot', 'new', 'top']}
optionNames={['Hot', 'New', 'Top']}
selected="hot"
/>
<Comments
{post}
nodes={buildCommentsTree(comments.comments, false)}
isParent={true}
/>
{:catch}
<div class="bg-red-500/10 border border-red-500 rounded-md p-4">
Failed to load comments.
<div class="mt-4 flex flex-col gap-2">
<div class="font-bold text-lg">
Comments <span class="text-sm font-normal ml-2 opacity-80">
{postData.counts.comments}
</span>
</div>
{#await data.streamed.comments}
<div class="flex flex-col gap-8">
{#each new Array(10) as comment}
<div class="flex flex-col gap-2">
<div
class="dark:bg-zinc-700 bg-slate-200 animate-pulse w-64 h-3 rounded-md"
/>
<div
class="dark:bg-zinc-700 bg-slate-200 animate-pulse w-128 h-4 rounded-md"
/>
</div>
{/each}
</div>
{:then comments}
{#if $user}
<CommentForm
postId={post.id}
on:comment={(comment) =>
(comments.comments = [
comment.detail.comment_view,
...comments.comments,
])}
/>
{/if}
<MultiSelect
options={['hot', 'new', 'top']}
optionNames={['Hot', 'New', 'Top']}
selected="hot"
/>
<Comments
{post}
nodes={buildCommentsTree(comments.comments, false)}
isParent={true}
/>
{:catch}
<div class="bg-red-500/10 border border-red-500 rounded-md p-4">
Failed to load comments.
</div>
{/await}
</div>
{/await}
</div>
<CommunityCard community_view={data.post.community_view} />
</div>