Skip to content

Commit

Permalink
translate distraction filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoussand committed Sep 20, 2023
1 parent 5c6b0c5 commit b1d66d7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
7 changes: 7 additions & 0 deletions public/locales/en/distraction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"distraction-1": "Did I eat lunch ?",
"distraction-2": "I have to go back to work...",
"distraction-3": "Ventilation is very noisy today. bzzzzzz",
"distraction-4": "Should I answer this message ?",
"distraction-5": "I have to focus, focus, focus"
}
7 changes: 7 additions & 0 deletions public/locales/fr/distraction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"distraction-1": "J'ai mangé ce midi ?",
"distraction-2": "Je dois retourner travailler...",
"distraction-3": "La ventilation fait beaucoup de bruit aujourd'hui. bzzzzzz",
"distraction-4": "Est-ce que je devrais répondre à ce message ?",
"distraction-5": "Je dois me concentrer, me concentrer, me concentrer"
}
19 changes: 17 additions & 2 deletions src/pages/egg.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CircularProgress } from "@mui/material";
import type { NextPage } from "next";
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import useSwr from "swr";

Expand All @@ -20,7 +21,17 @@ const EggPage: NextPage = () => {
fetcher
);

useSimulator([SIMULATE_EFFECT.DISTRACTIONS]);
const { t } = useTranslation();

const texts = [
t("distraction:distraction-1"),
t("distraction:distraction-2"),
t("distraction:distraction-3"),
t("distraction:distraction-4"),
t("distraction:distraction-5"),
];

useSimulator([SIMULATE_EFFECT.DISTRACTIONS], texts);

if (data === undefined || error) {
return <CircularProgress />;
Expand All @@ -40,7 +51,11 @@ export default EggPage;
export async function getStaticProps({ locale }: StaticProps) {
return {
props: {
...(await serverSideTranslations(locale, ["dairy_coffee_egg", "common"])),
...(await serverSideTranslations(locale, [
"dairy_coffee_egg",
"common",
"distraction",
])),
},
};
}
15 changes: 3 additions & 12 deletions src/simulators/distractions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
let distractionIntervale: NodeJS.Timer;

export const activeDistractions = () => {
scriptImportedFromExternalRepository();
export const activeDistractions = (texts: string[]) => {
scriptImportedFromExternalRepository(texts);
};

const timeouts: NodeJS.Timeout[] = [];

// used to save and clear timeouts
export const TIMEOUTS = {
timeouts,
Expand Down Expand Up @@ -73,7 +72,7 @@ function removeClass(element: string, classname: string) {
}
}

const scriptImportedFromExternalRepository = () => {
const scriptImportedFromExternalRepository = (texts: string[]) => {
function createElement(
element: string,
classname: string,
Expand All @@ -93,14 +92,6 @@ const scriptImportedFromExternalRepository = () => {
createElement("span", `wds-text-element-${index}`, text);
}

const texts = [
"J'ai mangé ce midi ?",
"Je dois retourner travailler...",
"La ventilation fait beaucoup de bruit aujourd'hui. bzzzzzz",
"Est-ce que je devrais répondre à ce message ?",
"Je dois me concentrer, me concentrer, me concentrer",
];

texts.forEach(createTextElements);

//add and remove animation classes, then loop
Expand Down
14 changes: 10 additions & 4 deletions src/simulators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import { activeScrambleLetter, removeScrambleLetter } from "./scrambleLetter";
import { COLOR_FILTER_ID, SIMULATE_EFFECT } from "./types";
import { activeFullZoom, resetZoom } from "./zoom";

export const useSimulator = (effects: SIMULATE_EFFECT[]) => {
export const useSimulator = (
effects: SIMULATE_EFFECT[],
texts: string[] = []
) => {
useEffect(() => {
activateSimulators(effects);
activateSimulators(effects, texts);

return () => removeSimulations();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -35,7 +38,10 @@ export const useColorFilterSimulator = (filterIds: COLOR_FILTER_ID[]) => {
}, filterIds);
};

export const activateSimulators = (effects: SIMULATE_EFFECT[]) => {
export const activateSimulators = (
effects: SIMULATE_EFFECT[],
texts: string[]
) => {
effects.forEach((effect) => {
switch (effect) {
case SIMULATE_EFFECT.ZOOM:
Expand All @@ -60,7 +66,7 @@ export const activateSimulators = (effects: SIMULATE_EFFECT[]) => {
activeScrambleLetter();
break;
case SIMULATE_EFFECT.DISTRACTIONS:
activeDistractions();
activeDistractions(texts);
break;
}
});
Expand Down

0 comments on commit b1d66d7

Please sign in to comment.