From dbb6f16fde17760dc79466c5bc9c210456248b4d Mon Sep 17 00:00:00 2001 From: Xylight Date: Wed, 11 Sep 2024 20:31:17 -0700 Subject: [PATCH] feat: add some stats to post actions --- package.json | 2 +- src/lib/components/lemmy/post/Post.svelte | 2 +- .../components/lemmy/post/PostActions.svelte | 66 ++++++++++++++++--- src/lib/components/lemmy/post/PostMeta.svelte | 17 ++++- .../lemmy/post/link/PostLinkSources.svelte | 11 ---- src/lib/components/ui/navbar/Profile.svelte | 1 - src/lib/i18n/en.json | 10 ++- .../post/[instance]/[id=integer]/+page.svelte | 2 +- 8 files changed, 81 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 83c6c193..b0934faf 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "linkify-it": "^5.0.0", "marked": "^5.1.2", "marked-linkify-it": "^3.1.10", - "mono-svelte": "^1.6.26", + "mono-svelte": "latest", "nprogress": "^0.2.0", "postcss": "^8.4.30", "rollup-plugin-visualizer": "^5.9.2", diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index 53bb1a54..27772d79 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -128,7 +128,7 @@ title={hideTitle ? undefined : tags?.title ? tags.title : post.post.name} read={post.read} style="grid-area: meta;" - edited={post.post.updated != undefined} + edited={post.post.updated} tags={tags?.tags} {view} > diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index 6f3f09ae..ab2007f8 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -3,6 +3,7 @@ import PostVote from './PostVote.svelte' import { getInstance, site } from '$lib/lemmy.js' import { + ArrowsUpDown, ArrowTopRightOnSquare, Bookmark, BookmarkSlash, @@ -11,6 +12,7 @@ ChatBubbleOvalLeft, ChatBubbleOvalLeftEllipsis, CheckBadge, + Clock, EllipsisHorizontal, Eye, EyeSlash, @@ -20,6 +22,7 @@ Language, MapPin, Newspaper, + Pencil, PencilSquare, ServerStack, Share, @@ -60,6 +63,9 @@ import { publishedToDate } from '$lib/components/util/date' import TextProps from '$lib/components/ui/text/TextProps.svelte' import { communityLink, userLink } from '$lib/lemmy/generic' + import RelativeDate, { + formatRelativeDate, + } from '$lib/components/util/RelativeDate.svelte' export let post: PostView export let view: View = 'cozy' @@ -214,6 +220,53 @@ > + {$t('cards.site.stats')} +
+ + + + {publishedToDate(post.post.published).toLocaleDateString(undefined, { + dateStyle: 'short', + })} + + + {#if post.post.updated} + {@const editedTime = formatRelativeDate( + publishedToDate(post.post.updated), + { + style: 'long', + } + )} + + + + + {/if} +
+ {#if post.counts.score} + {@const ratio = + post.counts.upvotes / (post.counts.upvotes + post.counts.downvotes)} + + + {$t('post.actions.vote.score')} + • + + • + + + {/if} {$t('post.actions.more.creator')} - -
- {$t('post.actions.more.actions')} + + {$t('post.actions.more.actions')} + {#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id} (editing = true)}> diff --git a/src/lib/components/lemmy/post/PostMeta.svelte b/src/lib/components/lemmy/post/PostMeta.svelte index 557e4cbb..394dc676 100644 --- a/src/lib/components/lemmy/post/PostMeta.svelte +++ b/src/lib/components/lemmy/post/PostMeta.svelte @@ -43,7 +43,9 @@ import Avatar from '$lib/components/ui/Avatar.svelte' import { Badge, Material, Popover } from 'mono-svelte' import UserLink from '$lib/components/lemmy/user/UserLink.svelte' - import RelativeDate from '$lib/components/util/RelativeDate.svelte' + import RelativeDate, { + formatRelativeDate, + } from '$lib/components/util/RelativeDate.svelte' import type { Community, Person, SubscribedType } from 'lemmy-js-client' import { Bookmark, @@ -65,6 +67,7 @@ import { t } from '$lib/translations' import { Pencil, type IconSource } from 'svelte-hero-icons' import CommunityHeader from '../community/CommunityHeader.svelte' + import { publishedToDate } from '$lib/components/util/date' export let community: Community | undefined = undefined export let showCommunity: boolean = true @@ -75,7 +78,7 @@ export let title: string | undefined = undefined export let id: number | undefined = undefined export let read: boolean = false - export let edited: boolean = false + export let edited: string | undefined = undefined export let view: View = 'cozy' @@ -167,7 +170,15 @@ {/if} {#if edited} - +
+ +
{/if}
- new URL(url).hostname.split('.').slice(-2).join('.') -{#if openMediaBias} - {#await import('$lib/components/mbfc/MBFCModal.svelte') then { default: MbfcModal }} - - {/await} -{/if} - diff --git a/src/lib/components/ui/navbar/Profile.svelte b/src/lib/components/ui/navbar/Profile.svelte index 46e5fe6a..69ec60fb 100644 --- a/src/lib/components/ui/navbar/Profile.svelte +++ b/src/lib/components/ui/navbar/Profile.svelte @@ -120,7 +120,6 @@ {$t('account.accounts')} -
{$t('nav.menu.app')} diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index 65f9ad40..0d331425 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -481,7 +481,8 @@ }, "vote": { "upvote": "Upvote", - "downvote": "Downvote" + "downvote": "Downvote", + "score": "Score" } }, "badges": { @@ -496,6 +497,10 @@ "zoomIn": "Zoom in", "zoomOut": "Zoom out", "close": "Close" + }, + "meta": { + "lastEdited": "Last edited {{default}}", + "created": "Created {{default}}" } }, "comment": { @@ -859,7 +864,8 @@ "vote": { "group": "Post voting controls", "upvotes": "{{default}} upvotes", - "downvotes": "{{default}} downvotes" + "downvotes": "{{default}} downvotes", + "score": "Score: {{default}}" } }, "stats": { diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index 909effb3..868910e7 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -204,7 +204,7 @@ moderator: post.post_view.creator_is_moderator, }} published={publishedToDate(post.post_view.post.published)} - edited={post.post_view.post.updated != undefined} + edited={post.post_view.post.updated} bind:title={post.post_view.post.name} style="width: max-content;" />