From 54b1cef68f55c2ace59d567e07d169bd836a09f0 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Thu, 6 Jul 2023 13:28:38 -0700 Subject: [PATCH] feat: Add upvote % --- src/lib/components/lemmy/Post.svelte | 8 + src/lib/components/ui/StickyCard.svelte | 4 +- src/routes/post/[instance]/[id]/+page.svelte | 206 ++++++++++--------- 3 files changed, 120 insertions(+), 98 deletions(-) diff --git a/src/lib/components/lemmy/Post.svelte b/src/lib/components/lemmy/Post.svelte index ca811015..7bcc0f2e 100644 --- a/src/lib/components/lemmy/Post.svelte +++ b/src/lib/components/lemmy/Post.svelte @@ -61,6 +61,14 @@ • + • + + {Math.floor( + (postRes.counts.upvotes / + (postRes.counts.upvotes + postRes.counts.downvotes || 1)) * + 100 + )}% +
diff --git a/src/lib/components/ui/StickyCard.svelte b/src/lib/components/ui/StickyCard.svelte index c946ea9e..091adbde 100644 --- a/src/lib/components/ui/StickyCard.svelte +++ b/src/lib/components/ui/StickyCard.svelte @@ -1,8 +1,8 @@ diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte index 2b68a8ff..0699bb5a 100644 --- a/src/routes/post/[instance]/[id]/+page.svelte +++ b/src/routes/post/[instance]/[id]/+page.svelte @@ -101,103 +101,117 @@ {data.post.post_view.post.name} -
- - -
- - - - • - - -
-
-

{post.name}

- {#if post.url} - - {post.url} - - {/if} - {#if isImage(post.url)} - {post.name} - {:else if isVideo(post.url)} - - - {/if} - {#if post.body} -

- -

- {/if} -
- -
-
-
-
- Comments - {postData.counts.comments} - -
- {#await data.streamed.comments} -
- {#each new Array(10) as comment} -
-
-
+
+
+
+ + +
+ + + + • + + • + + {Math.floor( + (data.post.post_view.counts.upvotes / + (data.post.post_view.counts.upvotes + + data.post.post_view.counts.downvotes || 1)) * + 100 + )}% + +
- {/each} +
+

{post.name}

+ {#if post.url} + + {post.url} + + {/if} + {#if isImage(post.url)} + {post.name} + {:else if isVideo(post.url)} + + + {/if} + {#if post.body} +

+ +

+ {/if} +
+ +
- {:then comments} - {#if $user} - - (comments.comments = [ - comment.detail.comment_view, - ...comments.comments, - ])} - /> - {/if} - - - {:catch} -
- Failed to load comments. +
+
+ Comments + {postData.counts.comments} + +
+ {#await data.streamed.comments} +
+ {#each new Array(10) as comment} +
+
+
+
+ {/each} +
+ {:then comments} + {#if $user} + + (comments.comments = [ + comment.detail.comment_view, + ...comments.comments, + ])} + /> + {/if} + + + {:catch} +
+ Failed to load comments. +
+ {/await}
- {/await} +
+