diff --git a/client/src/components/settings/LifelineCreationForm.tsx b/client/src/components/settings/LifelineCreationForm.tsx index bff2f9f..9bf9ee4 100644 --- a/client/src/components/settings/LifelineCreationForm.tsx +++ b/client/src/components/settings/LifelineCreationForm.tsx @@ -1,10 +1,16 @@ +import { compressToEncodedURIComponent } from 'lz-string' import { useEffect, useState } from 'react' import { useFullScreenHandle } from 'react-full-screen' +import { useNavigate } from 'react-router-dom' import styled from 'styled-components' import { ModuleResInterface } from '../../interfaces' +import { UpdateSettings } from '../../routing/UpdateSettings' +import { UpdateURL } from '../../routing/UpdateURL' import { + COMPRESSED_KEY, ERROR_MSG, + LANGUAGE_LOCAL_STORAGE_KEY, LIFELINES_LOCAL_STORAGE_KEY, URL, } from '../../utils/constants' @@ -63,6 +69,7 @@ const LifelineCreationForm = () => { const [lifelineModules, setLifelineModules] = useState( [], ) + const navigate = useNavigate() useEffect(() => { getData( diff --git a/client/src/components/ui/NavBar.tsx b/client/src/components/ui/NavBar.tsx index a220586..d88891b 100644 --- a/client/src/components/ui/NavBar.tsx +++ b/client/src/components/ui/NavBar.tsx @@ -204,10 +204,10 @@ function NavBar({ )} {!mobileWidth && ( <> - + Settings - + Lifelines diff --git a/client/src/components/utils/constants.ts b/client/src/components/utils/constants.ts index 930e239..5ad47af 100644 --- a/client/src/components/utils/constants.ts +++ b/client/src/components/utils/constants.ts @@ -1,6 +1,7 @@ -export const options = [ +export type Option = {value: string, label: string} +export const options: Option[] = [ { value: 'english', label: 'English' }, { value: 'spanish', label: 'Spanish' }, { value: 'hindi', label: 'Hindi' }, { value: 'mandarin', label: 'Mandarin' }, -] +] \ No newline at end of file diff --git a/client/src/pages/Home.tsx b/client/src/pages/Home.tsx index 242e27a..9dfb1bf 100644 --- a/client/src/pages/Home.tsx +++ b/client/src/pages/Home.tsx @@ -1,11 +1,14 @@ import { useEffect, useState } from 'react' import { FullScreen, useFullScreenHandle } from 'react-full-screen' +import { useNavigate } from 'react-router-dom' import Clock from '../components/clock/Clock' import Newsfeed from '../components/clock/Newsfeed' import Lifelines from '../components/lifelines/Lifelines' import NavBar from '../components/ui/NavBar' import { ModuleResInterface, NewsInterface } from '../interfaces/index' +import { UpdateSettings } from '../routing/UpdateSettings' +import { UpdateURL } from '../routing/UpdateURL' import { ERROR_MSG, NUM_LIFELINES_DISPLAYED, URL } from '../utils/constants' import { getData, getHeadlines } from '../utils/utils' @@ -17,6 +20,7 @@ export default function Home() { ) const [newsfeedModules, setNewsfeedModules] = useState([]) const [errorFlag, setErrorFlag] = useState(false) + const navigate = useNavigate() const handle = useFullScreenHandle() const [showFullscreenButton, setFullscreenButton] = useState(false) @@ -29,8 +33,16 @@ export default function Home() { setModules, setLifelineModules, setNewsfeedModules, - ) - }, [defaultLanguage]) + ).then(() => { + UpdateURL(navigate, defaultLanguage, lifelineModules) + UpdateSettings( + defaultLanguage, + setDefaultLanguage, + lifelineModules, + setLifelineModules, + ) + }) + }, [navigate, defaultLanguage, lifelineModules]) return ( <> diff --git a/client/src/pages/Settings.tsx b/client/src/pages/Settings.tsx index 85b5b36..6847545 100644 --- a/client/src/pages/Settings.tsx +++ b/client/src/pages/Settings.tsx @@ -1,11 +1,20 @@ -import { useState } from 'react' +import { compressToEncodedURIComponent } from 'lz-string' +import { useEffect, useState, useState } from 'react' import { useFullScreenHandle } from 'react-full-screen' +import { useNavigate } from 'react-router-dom' import styled from 'styled-components' import CopyButton from '../components/ui/CopyButton' import NavBar from '../components/ui/NavBar' import { StyledSelect } from '../components/ui/Select' -import { options } from '../components/utils/constants' +import { Option, options } from '../components/utils/constants' +import { UpdateSettings } from '../routing/UpdateSettings' +import { UpdateURL } from '../routing/UpdateURL' +import { + COMPRESSED_KEY, + LANGUAGE_LOCAL_STORAGE_KEY, + LIFELINES_LOCAL_STORAGE_KEY, +} from '../utils/constants' const SettingsHeading = styled.div` color: ${({ theme }) => theme.headerText}; @@ -55,6 +64,33 @@ const SelectContainer = styled.div` function Settings() { const handle = useFullScreenHandle() + const navigate = useNavigate() + const [selectedLanguage, setSelectedLanguage] = useState