feat: add support for all languages from old homarr (#1394)
* feat: add support for all languages from old homarr * fix: add mantine-react-table translations, remove arabic language * refactor: change translations to json for better crowdin support * fix: issues with loading dayjs and mantine-react-table translations * chore: add additional translations with variables * fix: format and deepsource issues * fix: test failing because of missing coverage exclusions * fix: format issues * fix: format issue
This commit is contained in:
@@ -1,25 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import dayjs from "dayjs";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
const calculateTimeAgo = (timestamp: Date, locale: string) => {
|
||||
return dayjs().locale(locale).to(timestamp);
|
||||
const calculateTimeAgo = (timestamp: Date) => {
|
||||
return dayjs().to(timestamp);
|
||||
};
|
||||
|
||||
export const useTimeAgo = (timestamp: Date) => {
|
||||
const { locale } = useParams<{ locale: string }>();
|
||||
const [timeAgo, setTimeAgo] = useState(calculateTimeAgo(timestamp, locale));
|
||||
const [timeAgo, setTimeAgo] = useState(calculateTimeAgo(timestamp));
|
||||
|
||||
useEffect(() => {
|
||||
const intervalId = setInterval(() => setTimeAgo(calculateTimeAgo(timestamp, locale)), 1000); // update every second
|
||||
const intervalId = setInterval(() => setTimeAgo(calculateTimeAgo(timestamp)), 1000); // update every second
|
||||
|
||||
return () => clearInterval(intervalId); // clear interval on hook unmount
|
||||
}, [timestamp, locale]);
|
||||
}, [timestamp]);
|
||||
|
||||
return timeAgo;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user