diff --git a/src/app/context/language.tsx b/src/app/context/language.tsx index 45b1d69..02c07f5 100644 --- a/src/app/context/language.tsx +++ b/src/app/context/language.tsx @@ -1,5 +1,5 @@ "use client" -import { createContext, useContext, useState, ReactNode } from "react"; +import { createContext, useContext, useState, ReactNode, useEffect } from "react"; interface LanguageContextProviderProps { @@ -15,15 +15,33 @@ interface LanguageContextValue const LanguageContext = createContext(undefined); export const LanguageContextProvider = ({ children }: LanguageContextProviderProps) => { - const [language, setLanguage] = useState('Spanish'); - - console.log(navigator.language) - - return ( - - {children} - - ); + + const detectLanguage = ():string => { //function used to execute useEffect before useState + if (navigator.language.includes('es')) + { + return 'Spanish'; + } + else + { + return 'English'; + } + }; + + const startLanguage = detectLanguage(); + + useEffect(() => { + setLanguage(startLanguage); + }, []); + + const [language, setLanguage] = useState(startLanguage); + + console.log(navigator.language) + + return ( + + {children} + + ); }; export const useLanguageContext = (): LanguageContextValue => { diff --git a/src/app/page.tsx b/src/app/page.tsx index 40c86c6..64bb67e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,5 @@ "use client"; -import React, {use, useState} from 'react'; +import React, {useState} from 'react'; import styles from '../css/page.module.css'; import Terminal from '@/components/Terminal'; import Typewriter from '@/components/Typewriter'; diff --git a/src/components/LanguageSwitch.tsx b/src/components/LanguageSwitch.tsx index 2ea5628..ab1a405 100644 --- a/src/components/LanguageSwitch.tsx +++ b/src/components/LanguageSwitch.tsx @@ -27,7 +27,7 @@ const Typewriter = () => { const changeState = (language:string) => { setLanguage(language); - }; + }; console.log(language) //TODO delete this line return ( @@ -37,9 +37,10 @@ const Typewriter = () => { className={styles.checkbox} type="radio" name='language' + checked={language=='English'} onClick={() => changeState('English')} /> - +
{ type="radio" id='language' name='language' + checked={language=='Spanish'} onClick={() => changeState('Spanish')} /> - +
) diff --git a/src/css/switch.module.css b/src/css/switch.module.css index d87b132..88ca63a 100644 --- a/src/css/switch.module.css +++ b/src/css/switch.module.css @@ -2,8 +2,8 @@ { display: flex; flex-direction: row; - justify-content: space-between; align-items: center; + justify-content: center; height: 100%; width: 30%; font-size: 3.2vh; @@ -21,7 +21,6 @@ { display: flex; flex-direction: row; - justify-content: space-between; align-items: center; height: 100%; width: 50%; @@ -40,6 +39,7 @@ -webkit-appearance: none; outline: none; cursor: pointer; + margin-right:10%; } .checkbox:checked { @@ -56,18 +56,20 @@ { width: 50%; font-size: 2vh; + justify-content: space-between; } .languageSwitchContainer { display: flex; flex-direction: row; height: 100%; + justify-content: center; } .section { width: 50%; - justify-content: space-around; font-size: 2vh; + justify-content: center; } }