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} /> <UserLink user={postRes.creator} />
<span>•</span> <span>•</span>
<RelativeDate date={new Date(postRes.post.published)} /> <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> </span>
</div> </div>
<div class="ml-auto" /> <div class="ml-auto" />
+2 -2
View File
@@ -1,8 +1,8 @@
<div <div
class="sticky top-20 border bg-white shadow-md border-slate-100 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 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)] flex-col gap-4 p-8 max-w-[20rem] min-w-[20rem] rounded-md h-max max-h-[calc(100vh-6rem)]
overflow-auto w-full" overflow-auto"
> >
<slot /> <slot />
</div> </div>
+110 -96
View File
@@ -101,103 +101,117 @@
<title>{data.post.post_view.post.name}</title> <title>{data.post.post_view.post.name}</title>
</svelte:head> </svelte:head>
<div class="flex flex-col gap-2"> <div class="flex flex-row gap-4">
<span class="flex flex-row gap-2 text-sm opacity-80 items-center"> <div>
<Avatar <div class="flex flex-col gap-2">
url={postData.community.icon} <span class="flex flex-row gap-2 text-sm opacity-80 items-center">
width={24} <Avatar
alt={postData.community.name} url={postData.community.icon}
/> width={24}
<div class="flex flex-col text-xs"> alt={postData.community.name}
<CommunityLink community={postData.community} /> />
<span class="opacity-50 flex flex-row gap-1"> <div class="flex flex-col text-xs">
<UserLink user={postData.creator} /> <CommunityLink community={postData.community} />
<span>•</span> <span class="opacity-50 flex flex-row gap-1">
<RelativeDate date={new Date(postData.post.published)} /> <UserLink user={postData.creator} />
</span> <span>•</span>
</div> <RelativeDate date={new Date(postData.post.published)} />
</span> <span>•</span>
<h1 class="font-bold text-lg">{post.name}</h1> <span>
{#if post.url} {Math.floor(
<a (data.post.post_view.counts.upvotes /
href={post.url} (data.post.post_view.counts.upvotes +
class="text-sky-400 max-w-[48ch] overflow-hidden data.post.post_view.counts.downvotes || 1)) *
whitespace-nowrap text-ellipsis text-xs hover:underline" 100
> )}%
{post.url} </span>
</a> </span>
{/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> </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> </div>
{:then comments} <div class="mt-4 flex flex-col gap-2">
{#if $user} <div class="font-bold text-lg">
<CommentForm Comments <span class="text-sm font-normal ml-2 opacity-80">
postId={post.id} {postData.counts.comments}
on:comment={(comment) => </span>
(comments.comments = [ </div>
comment.detail.comment_view, {#await data.streamed.comments}
...comments.comments, <div class="flex flex-col gap-8">
])} {#each new Array(10) as comment}
/> <div class="flex flex-col gap-2">
{/if} <div
<MultiSelect class="dark:bg-zinc-700 bg-slate-200 animate-pulse w-64 h-3 rounded-md"
options={['hot', 'new', 'top']} />
optionNames={['Hot', 'New', 'Top']} <div
selected="hot" class="dark:bg-zinc-700 bg-slate-200 animate-pulse w-128 h-4 rounded-md"
/> />
<Comments </div>
{post} {/each}
nodes={buildCommentsTree(comments.comments, false)} </div>
isParent={true} {:then comments}
/> {#if $user}
{:catch} <CommentForm
<div class="bg-red-500/10 border border-red-500 rounded-md p-4"> postId={post.id}
Failed to load comments. 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> </div>
{/await} </div>
<CommunityCard community_view={data.post.community_view} />
</div> </div>