Skip to content

Commit

Permalink
navigator error solved
Browse files Browse the repository at this point in the history
  • Loading branch information
AB10110F committed Aug 17, 2023
1 parent a8b38b2 commit 7d5f929
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
26 changes: 18 additions & 8 deletions src/app/context/language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ interface LanguageContextProviderProps
children: ReactNode;
}

interface Navigator {
// Properties
readonly language: string;
}

interface LanguageContextValue
{
language: string;
Expand All @@ -17,13 +22,20 @@ const LanguageContext = createContext<LanguageContextValue | undefined>(undefine
export const LanguageContextProvider = ({ children }: LanguageContextProviderProps) => {

const detectLanguage = ():string => { //function used to execute useEffect before useState
if (navigator.language.includes('es'))
{
return 'Spanish';
}
else
if (typeof navigator !== "undefined") {
// browser code
if ((navigator as Navigator).language.includes('es'))
{
return 'Spanish';
}
else
{
return 'English';
}
}
else
{
return 'English';
return '';
}
};

Expand All @@ -35,8 +47,6 @@ export const LanguageContextProvider = ({ children }: LanguageContextProviderPro

const [language, setLanguage] = useState(startLanguage);

console.log(navigator.language)

return (
<LanguageContext.Provider value={{ language, setLanguage }}>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export default function RootLayout({
</body>
</html>
)
}
}
3 changes: 2 additions & 1 deletion src/components/CrtSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ const CrtSwtich: React.FC<CrtProps> = ({ changeState }) => {
<section className={styles.container}>
<input
className={styles.checkbox}
id='crtSwitch'
type="checkbox"
checked={crt}
onChange={handleChange}
/>
<label style={vt323.style} htmlFor="">{label}</label>
<label style={vt323.style} htmlFor="crtSwitch">{label}</label>
</section>
);
};
Expand Down
17 changes: 8 additions & 9 deletions src/components/LanguageSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {useState, useEffect, useRef} from 'react';
import styles from '../css/switch.module.css'
import { vt323 } from '../fonts/fonts';
import { useLanguageContext } from '../app/context/language';

const Typewriter = () => {
const LanguageSwitch = () => {
const {language, setLanguage} = useLanguageContext();

let l1:string
Expand All @@ -28,7 +27,6 @@ const Typewriter = () => {
const changeState = (language:string) => {
setLanguage(language);
};
console.log(language) //TODO delete this line

return (
<section className={styles.languageSwitchContainer}>
Expand All @@ -37,24 +35,25 @@ const Typewriter = () => {
className={styles.checkbox}
type="radio"
name='language'
id="english"
checked={language=='English'}
onClick={() => changeState('English')}
onChange={() => changeState('English')}
/>
<label style={vt323.style} htmlFor="" >{l1}</label>
<label style={vt323.style} htmlFor="english" >{l1}</label>
</section>
<section className={styles.section}>
<input
className={styles.checkbox}
type="radio"
id='language'
id='spanish'
name='language'
checked={language=='Spanish'}
onClick={() => changeState('Spanish')}
onChange={() => changeState('Spanish')}
/>
<label style={vt323.style} htmlFor="" >{l2}</label>
<label style={vt323.style} htmlFor="spanish" >{l2}</label>
</section>
</section>
)
};

export default Typewriter;
export default LanguageSwitch;
1 change: 1 addition & 0 deletions src/components/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ const Terminal = () => {
ref={inputRef}
style={vt323.style}
type="text"
id='prompt'
value={input}
onChange={e=>setInput(e.target.value)}
onKeyDown={e=>{
Expand Down
1 change: 1 addition & 0 deletions src/css/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
background-color: black; /*TODO*/
--background-end-rgb: 0, 0, 0;

--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
Expand Down
1 change: 0 additions & 1 deletion src/css/switch.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
{
width: 50%;
font-size: 2vh;
justify-content: space-between;
}
.languageSwitchContainer
{
Expand Down
2 changes: 1 addition & 1 deletion src/css/terminal.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

.history
{
padding: 15px;
padding: 15px 15px 0px 15px;
/* white-space: pre-wrap;
word-wrap: break-word; */
width: 100%;
Expand Down

0 comments on commit 7d5f929

Please sign in to comment.