From 10caa8b768c21b6996aabb51638b918c9e5f2959 Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Sun, 7 Apr 2024 20:38:21 +0200 Subject: [PATCH] adds time string to comment card --- .../components/comment/comment_card.svelte | 17 +++++++++-- .../components/trail/trail_info_panel.svelte | 4 +-- web/src/lib/i18n/locales/de.json | 1 + web/src/lib/i18n/locales/en.json | 6 ++++ web/src/lib/i18n/locales/fr.json | 1 + web/src/lib/i18n/locales/hu.json | 1 + web/src/lib/i18n/locales/nl.json | 1 + web/src/lib/i18n/locales/pl.json | 1 + web/src/lib/i18n/locales/pt.json | 1 + web/src/lib/i18n/locales/zh.json | 1 + web/src/lib/models/comment.ts | 1 + web/src/lib/util/format_util.ts | 28 +++++++++++++++++++ 12 files changed, 58 insertions(+), 5 deletions(-) diff --git a/web/src/lib/components/comment/comment_card.svelte b/web/src/lib/components/comment/comment_card.svelte index 00de1cf4..819acedf 100644 --- a/web/src/lib/components/comment/comment_card.svelte +++ b/web/src/lib/components/comment/comment_card.svelte @@ -4,6 +4,8 @@ import { createEventDispatcher } from "svelte"; import TextField from "../base/text_field.svelte"; import { fade } from "svelte/transition"; + import { formatTimeSince } from "$lib/util/format_util"; + import { _ } from "svelte-i18n"; export let comment: Comment; export let mode: "show" | "edit" = "show"; @@ -14,10 +16,12 @@ let editedComment = comment.text; - const avatarSrc = comment.expand?.author.avatar + $: avatarSrc = comment.expand?.author.avatar ? getFileURL(comment.expand.author, comment.expand.author.avatar) : `https://api.dicebear.com/7.x/initials/svg?seed=${comment.expand?.author.username ?? ""}&backgroundType=gradientLinear`; + $: timeSince = formatTimeSince(new Date(comment.created ?? "")); + function deleteComment() { dispatch("delete", comment); } @@ -38,8 +42,15 @@ avatar
-

- {comment.expand?.author.username} +

+ {comment.expand?.author.username} + {$_(`n-${timeSince.unit}-ago`, { + values: { n: timeSince.value }, + })}

{#if mode == "edit"}