From 7956e9fa6772ab57a0794fb7cba7e9d9c0bd7878 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 28 Dec 2024 12:30:24 +0000 Subject: feat: Implement the all highlights page. Fixes #620 --- apps/web/lib/hooks/relative-time.ts | 22 ++++++++++++++++++++++ apps/web/lib/i18n/locales/en/translation.json | 1 + 2 files changed, 23 insertions(+) create mode 100644 apps/web/lib/hooks/relative-time.ts (limited to 'apps/web/lib') diff --git a/apps/web/lib/hooks/relative-time.ts b/apps/web/lib/hooks/relative-time.ts new file mode 100644 index 00000000..f7c38497 --- /dev/null +++ b/apps/web/lib/hooks/relative-time.ts @@ -0,0 +1,22 @@ +import { useEffect, useState } from "react"; +import dayjs from "dayjs"; +import relativeTime from "dayjs/plugin/relativeTime"; + +dayjs.extend(relativeTime); + +export default function useRelativeTime(date: Date) { + const [state, setState] = useState({ + fromNow: "", + localCreatedAt: "", + }); + + // This is to avoid hydration errors when server and clients are in different timezones + useEffect(() => { + setState({ + fromNow: dayjs(date).fromNow(), + localCreatedAt: date.toLocaleString(), + }); + }, [date]); + + return state; +} diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.json index 9caad519..2812df88 100644 --- a/apps/web/lib/i18n/locales/en/translation.json +++ b/apps/web/lib/i18n/locales/en/translation.json @@ -20,6 +20,7 @@ "note": "Note", "attachments": "Attachments", "highlights": "Highlights", + "source": "Source", "screenshot": "Screenshot", "video": "Video", "archive": "Archive", -- cgit v1.2.3-70-g09d2