mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
fix randomized titles
This commit is contained in:
parent
9bfad15a57
commit
0883942093
2 changed files with 14 additions and 6 deletions
|
@ -1,15 +1,22 @@
|
||||||
|
import { useCallback, useMemo } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export function useRandomTranslation() {
|
export function useRandomTranslation() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const seed = useMemo(() => Math.random(), []);
|
||||||
|
|
||||||
const getRandomTranslation = (key: string) => {
|
const getRandomTranslation = useCallback(
|
||||||
|
(key: string) => {
|
||||||
const res = t(key, { returnObjects: true });
|
const res = t(key, { returnObjects: true });
|
||||||
|
|
||||||
if (Array.isArray(res)) return res[Math.floor(Math.random() * res.length)];
|
if (Array.isArray(res)) {
|
||||||
|
return res[Math.floor(seed * res.length)];
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
},
|
||||||
|
[t, seed]
|
||||||
|
);
|
||||||
|
|
||||||
return { t: getRandomTranslation };
|
return { t: getRandomTranslation };
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@ export function HeroPart({ setIsSticky, searchParams }: HeroPartProps) {
|
||||||
let time = "night";
|
let time = "night";
|
||||||
const hour = new Date().getHours();
|
const hour = new Date().getHours();
|
||||||
if (hour < 12) time = "morning";
|
if (hour < 12) time = "morning";
|
||||||
if (hour < 19) time = "day";
|
else if (hour < 19) time = "day";
|
||||||
|
|
||||||
const title = t(`search.title.${time}`);
|
const title = t(`search.title.${time}`);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue