From 66eca58d01bf14726710c0ca6171854ade39ed09 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Thu, 6 Jul 2023 17:05:20 -0700 Subject: [PATCH] misc: gpt did a goofy --- src/hooks.server.ts | 1 + src/lib/components/lemmy/Post.svelte | 12 +++++++----- src/lib/components/util/RelativeDate.svelte | 9 ++------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 1ed56b8f..5c14777c 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -9,6 +9,7 @@ function buildUrl(inputUrl: URL): URL { } export function handleError({ error, event }) { + console.error(error) return { message: 'There was an error during rendering', } diff --git a/src/lib/components/lemmy/Post.svelte b/src/lib/components/lemmy/Post.svelte index 7bcc0f2e..f0225d38 100644 --- a/src/lib/components/lemmy/Post.svelte +++ b/src/lib/components/lemmy/Post.svelte @@ -141,11 +141,13 @@ Post Actions { - navigator.clipboard.writeText( - `${$page.url.origin}/post/${ - $authData?.instance ?? DEFAULT_INSTANCE_URL - }/${postRes.post.id}` - ) + if (typeof navigator != 'undefined') { + navigator.clipboard.writeText( + `${$page.url.origin}/post/${ + $authData?.instance ?? DEFAULT_INSTANCE_URL + }/${postRes.post.id}` + ) + } }} > diff --git a/src/lib/components/util/RelativeDate.svelte b/src/lib/components/util/RelativeDate.svelte index 3a8d82bd..d5a5e4ec 100644 --- a/src/lib/components/util/RelativeDate.svelte +++ b/src/lib/components/util/RelativeDate.svelte @@ -4,10 +4,8 @@ function formatRelativeDate(date: Date) { const now = Date.now() - // Calculate the difference in milliseconds between 'now' and 'date' const diffInMillis = now - date.getTime() - // Define time thresholds for different units (milliseconds) const thresholds = [ { unit: 'second', threshold: 1000 }, { unit: 'minute', threshold: 60 * 1000 }, @@ -16,16 +14,13 @@ { unit: 'week', threshold: 7 * 24 * 60 * 60 * 1000 }, { unit: 'month', threshold: 30 * 24 * 60 * 60 * 1000 }, { unit: 'year', threshold: 365 * 24 * 60 * 60 * 1000 }, - // You can add more units as needed, e.g., week, month, year ] - // Iterate through the thresholds to find the appropriate unit to display for (let i = thresholds.length - 1; i >= 0; i--) { if (diffInMillis >= thresholds[i].threshold) { const value = Math.round(diffInMillis / thresholds[i].threshold) - // Create a RelativeTimeFormat instance with user's locale and options - const rtf = new Intl.RelativeTimeFormat(navigator.language, { + const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'always', style: 'long', }) @@ -34,7 +29,7 @@ } } - return 'Now' // If none of the above conditions match defaulting to "Now" + return 'Now' }