adds time string to comment card
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import TextField from "../base/text_field.svelte";
|
import TextField from "../base/text_field.svelte";
|
||||||
import { fade } from "svelte/transition";
|
import { fade } from "svelte/transition";
|
||||||
|
import { formatTimeSince } from "$lib/util/format_util";
|
||||||
|
import { _ } from "svelte-i18n";
|
||||||
|
|
||||||
export let comment: Comment;
|
export let comment: Comment;
|
||||||
export let mode: "show" | "edit" = "show";
|
export let mode: "show" | "edit" = "show";
|
||||||
@@ -14,10 +16,12 @@
|
|||||||
|
|
||||||
let editedComment = comment.text;
|
let editedComment = comment.text;
|
||||||
|
|
||||||
const avatarSrc = comment.expand?.author.avatar
|
$: avatarSrc = comment.expand?.author.avatar
|
||||||
? getFileURL(comment.expand.author, 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`;
|
: `https://api.dicebear.com/7.x/initials/svg?seed=${comment.expand?.author.username ?? ""}&backgroundType=gradientLinear`;
|
||||||
|
|
||||||
|
$: timeSince = formatTimeSince(new Date(comment.created ?? ""));
|
||||||
|
|
||||||
function deleteComment() {
|
function deleteComment() {
|
||||||
dispatch("delete", comment);
|
dispatch("delete", comment);
|
||||||
}
|
}
|
||||||
@@ -38,8 +42,15 @@
|
|||||||
<img class="rounded-full w-10 aspect-square" src={avatarSrc} alt="avatar" />
|
<img class="rounded-full w-10 aspect-square" src={avatarSrc} alt="avatar" />
|
||||||
<div>
|
<div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<p class="text-sm font-semibold">
|
<p class="">
|
||||||
{comment.expand?.author.username}
|
<span class="text-sm font-semibold"
|
||||||
|
>{comment.expand?.author.username}</span
|
||||||
|
>
|
||||||
|
<span class="text-xs text-gray-500 ml-2"
|
||||||
|
>{$_(`n-${timeSince.unit}-ago`, {
|
||||||
|
values: { n: timeSince.value },
|
||||||
|
})}</span
|
||||||
|
>
|
||||||
</p>
|
</p>
|
||||||
{#if mode == "edit"}
|
{#if mode == "edit"}
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -232,7 +232,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<section class="trail-info-panel-content px-8">
|
<section class="trail-info-panel-content px-8">
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-1 mt-4 gap-8"
|
class="grid grid-cols-1 my-4 gap-8"
|
||||||
class:md:grid-cols-[1fr_18rem]={mode == "overview"}
|
class:md:grid-cols-[1fr_18rem]={mode == "overview"}
|
||||||
>
|
>
|
||||||
{#if activeTab == 0}
|
{#if activeTab == 0}
|
||||||
@@ -310,7 +310,7 @@
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<ul>
|
<ul class="space-y-4">
|
||||||
{#each trail.expand.comments_via_trail ?? [] as comment}
|
{#each trail.expand.comments_via_trail ?? [] as comment}
|
||||||
<li>
|
<li>
|
||||||
<CommentCard
|
<CommentCard
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "Metrisch",
|
"metric": "Metrisch",
|
||||||
"moderate": "Mittel",
|
"moderate": "Mittel",
|
||||||
"must-be-at-least-n-characters-long": "Muss mindestens {n} Zeichen lang sein",
|
"must-be-at-least-n-characters-long": "Muss mindestens {n} Zeichen lang sein",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"near": "Nahe",
|
"near": "Nahe",
|
||||||
"new-list": "Neue Liste",
|
"new-list": "Neue Liste",
|
||||||
|
|||||||
@@ -83,6 +83,12 @@
|
|||||||
"metric": "Metric",
|
"metric": "Metric",
|
||||||
"moderate": "Moderate",
|
"moderate": "Moderate",
|
||||||
"must-be-at-least-n-characters-long": "Must be at least {n} characters long",
|
"must-be-at-least-n-characters-long": "Must be at least {n} characters long",
|
||||||
|
"n-years-ago": "{n} years ago",
|
||||||
|
"n-months-ago": "{n} months ago",
|
||||||
|
"n-days-ago": "{n} days ago",
|
||||||
|
"n-hours-ago": "{n} hours ago",
|
||||||
|
"n-minutes-ago": "{n} minutes ago",
|
||||||
|
"n-seconds-ago": "{n} seconds ago",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"near": "Near",
|
"near": "Near",
|
||||||
"new-list": "New List",
|
"new-list": "New List",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "Métrique",
|
"metric": "Métrique",
|
||||||
"moderate": "Modérer",
|
"moderate": "Modérer",
|
||||||
"must-be-at-least-n-characters-long": "Doit être composé d'au moins {n} caractères",
|
"must-be-at-least-n-characters-long": "Doit être composé d'au moins {n} caractères",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"near": "Proche",
|
"near": "Proche",
|
||||||
"new-list": "Nouvelle liste",
|
"new-list": "Nouvelle liste",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "Metrikus",
|
"metric": "Metrikus",
|
||||||
"moderate": "Mérsékelt",
|
"moderate": "Mérsékelt",
|
||||||
"must-be-at-least-n-characters-long": "Legalább {n} karakter hosszúnak kell lennie",
|
"must-be-at-least-n-characters-long": "Legalább {n} karakter hosszúnak kell lennie",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "Név",
|
"name": "Név",
|
||||||
"near": "Közelben",
|
"near": "Közelben",
|
||||||
"new-list": "Új lista",
|
"new-list": "Új lista",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "Metrisch",
|
"metric": "Metrisch",
|
||||||
"moderate": "Gemiddeld",
|
"moderate": "Gemiddeld",
|
||||||
"must-be-at-least-n-characters-long": "Minimaal {n} tekens",
|
"must-be-at-least-n-characters-long": "Minimaal {n} tekens",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "Naam",
|
"name": "Naam",
|
||||||
"near": "Nabij",
|
"near": "Nabij",
|
||||||
"new-list": "Nieuwe lijst",
|
"new-list": "Nieuwe lijst",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "Metryczne",
|
"metric": "Metryczne",
|
||||||
"moderate": "Średnia",
|
"moderate": "Średnia",
|
||||||
"must-be-at-least-n-characters-long": "Długość musi wynosić przynajmniej {n} znaków",
|
"must-be-at-least-n-characters-long": "Długość musi wynosić przynajmniej {n} znaków",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "Nazwa",
|
"name": "Nazwa",
|
||||||
"near": "Blisko",
|
"near": "Blisko",
|
||||||
"new-list": "Nowa Lista",
|
"new-list": "Nowa Lista",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "Métrica",
|
"metric": "Métrica",
|
||||||
"moderate": "Moderado",
|
"moderate": "Moderado",
|
||||||
"must-be-at-least-n-characters-long": "Deve ter pelo menos {n} caracteres",
|
"must-be-at-least-n-characters-long": "Deve ter pelo menos {n} caracteres",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "Nome",
|
"name": "Nome",
|
||||||
"near": "Próximo",
|
"near": "Próximo",
|
||||||
"new-list": "Nova lista",
|
"new-list": "Nova lista",
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"metric": "公制",
|
"metric": "公制",
|
||||||
"moderate": "中等",
|
"moderate": "中等",
|
||||||
"must-be-at-least-n-characters-long": "长度至少 {n} 字符",
|
"must-be-at-least-n-characters-long": "长度至少 {n} 字符",
|
||||||
|
"n-years-ago": "",
|
||||||
"name": "名称",
|
"name": "名称",
|
||||||
"near": "附近",
|
"near": "附近",
|
||||||
"new-list": "新列表",
|
"new-list": "新列表",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export class Comment {
|
|||||||
rating: number;
|
rating: number;
|
||||||
author: string;
|
author: string;
|
||||||
trail: string;
|
trail: string;
|
||||||
|
created?: string;
|
||||||
expand?: {
|
expand?: {
|
||||||
author: User
|
author: User
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,3 +48,31 @@ export function formatElevation(meters?: number) {
|
|||||||
return `${Math.round(feet)} ft`;
|
return `${Math.round(feet)} ft`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatTimeSince(date: Date) {
|
||||||
|
|
||||||
|
var seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
|
||||||
|
|
||||||
|
var interval = seconds / 31536000;
|
||||||
|
|
||||||
|
if (interval > 1) {
|
||||||
|
return { unit: "years", value: Math.floor(interval) };
|
||||||
|
}
|
||||||
|
interval = seconds / 2592000;
|
||||||
|
if (interval > 1) {
|
||||||
|
return { unit: "months", value: Math.floor(interval) };
|
||||||
|
}
|
||||||
|
interval = seconds / 86400;
|
||||||
|
if (interval > 1) {
|
||||||
|
return { unit: "days", value: Math.floor(interval) };
|
||||||
|
}
|
||||||
|
interval = seconds / 3600;
|
||||||
|
if (interval > 1) {
|
||||||
|
return { unit: "hours", value: Math.floor(interval) };
|
||||||
|
}
|
||||||
|
interval = seconds / 60;
|
||||||
|
if (interval > 1) {
|
||||||
|
return { unit: "minutes", value: Math.floor(interval) };
|
||||||
|
}
|
||||||
|
return { unit: "seconds", value: Math.floor(interval) };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user