-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom URL generator #46
base: main
Are you sure you want to change the base?
Changes from 13 commits
fcd1d0b
f74840d
0a6b759
1f6544c
9339620
9c6723f
80d14e6
4db64d7
0994506
241d700
e5a0ce0
ec4ec28
1fd3832
2cf8dbc
580213d
e22f66f
e13e90b
d7e2799
6338945
9466479
93b02e5
09d6957
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { useState } from 'react' | ||
import { WindowSize } from '@reach/window-size' | ||
import { ThemeProvider } from 'styled-components' | ||
// import { get } from './api/config' | ||
import { BrowserRouter, Routes, Route } from 'react-router-dom' | ||
import { FullScreen, useFullScreenHandle } from 'react-full-screen' | ||
import GlobalStyle, { theme } from './components/ui/GlobalStyle' | ||
|
@@ -9,25 +10,26 @@ import LifelineCreation from './pages/lifelineCreation' | |
import EnterFullScreen from './components/buttons/EnterFullscreen' | ||
import ExitFullScreen from './components/buttons/ExitFullscreen' | ||
import Home from './pages/Home' | ||
|
||
function App() { | ||
const [showFullscreenButton, setFullscreenButton] = useState(false) | ||
/* Sets the lifeline modules upon load and every defaultLanguage change */ | ||
const handle = useFullScreenHandle() | ||
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<FullScreen | ||
handle={handle} | ||
onChange={() => setFullscreenButton(!showFullscreenButton)} | ||
> | ||
{' '} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also the space, i just may not be familiar with the syntax though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets added by the linter sometimes but it should be removed |
||
<BrowserRouter> | ||
<Routes> | ||
<Route path="/settings" element={<LanguageCustomization />} /> | ||
<Route path="/lifelines" element={<LifelineCreation />} /> | ||
<Route path="/" element={<Home />} /> | ||
<Route path="/langForm/*" element={<LanguageCustomization />} /> | ||
<Route path="/moduleForm/*" element={<LifelineCreation />} /> | ||
<Route path="/settings/*" element={<LanguageCustomization />} /> | ||
<Route path="/lifelines/*" element={<LifelineCreation />} /> | ||
<Route path="/*" element={<Home />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
|
||
{showFullscreenButton ? ( | ||
<EnterFullScreen handle={handle.enter} /> | ||
) : ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,16 @@ import { | |
URL, | ||
ERROR_MSG, | ||
LIFELINES_LOCAL_STORAGE_KEY, | ||
LANGUAGE_LOCAL_STORAGE_KEY, | ||
COMPRESSED_KEY, | ||
} from '../../utils/constants' | ||
import { compressToEncodedURIComponent } from 'lz-string' | ||
import { useNavigate } from 'react-router-dom' | ||
import { ModuleResInterface } from '../../interfaces' | ||
import { getData } from '../../utils/utils' | ||
import DraggableLifelines from '../DraggableLifelines' | ||
|
||
import { UpdateURL } from '../../routing/UpdateURL' | ||
import { UpdateSettings } from '../../routing/UpdateSettings' | ||
const LifelineCreationForm = () => { | ||
/* Lifeline module properties */ | ||
const flavor = 'Lifeline' | ||
|
@@ -22,6 +27,7 @@ const LifelineCreationForm = () => { | |
const [lifelineModules, setLifelineModules] = useState<ModuleResInterface[]>( | ||
[], | ||
) | ||
const navigate = useNavigate() | ||
|
||
useEffect(() => { | ||
getData( | ||
|
@@ -32,7 +38,9 @@ const LifelineCreationForm = () => { | |
setModules, | ||
setLifelineModules, | ||
) | ||
}, []) | ||
UpdateURL(navigate, null, lifelineModules) | ||
UpdateSettings(null, lifelineModules) | ||
}, [navigate, lifelineModules]) | ||
|
||
/* clearProperties | ||
* | ||
|
@@ -52,6 +60,18 @@ const LifelineCreationForm = () => { | |
*/ | ||
const formSubmit = (e: any) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend against using the any type since it is both bad practice and the linter will complain about this in the future |
||
e.preventDefault() | ||
/*const language: string | null = localStorage.getItem( | ||
LANGUAGE_LOCAL_STORAGE_KEY, | ||
)*/ | ||
let json = { | ||
language: localStorage.getItem(LANGUAGE_LOCAL_STORAGE_KEY), | ||
lifelines: lifelineModules, | ||
} | ||
const settings_json = JSON.stringify(json) | ||
let compressed = compressToEncodedURIComponent(settings_json) | ||
navigate(`${compressed}`) | ||
localStorage.setItem(COMPRESSED_KEY, compressed) | ||
|
||
const llModule: ModuleResInterface = { | ||
labels: [title] /* stored as array in API response */, | ||
flavor, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ import { ERROR_MSG, URL, NUM_LIFELINES_DISPLAYED } from '../utils/constants' | |
import { getData } from '../utils/utils' | ||
import Lifelines from '../components/lifelines/Lifelines' | ||
import { ModuleResInterface, NewsInterface } from '../interfaces/index' | ||
|
||
import { UpdateURL } from '../routing/UpdateURL' | ||
import { UpdateSettings } from '../routing/UpdateSettings' | ||
import { useNavigate } from 'react-router-dom' | ||
export default function Home() { | ||
const [defaultLanguage, setDefaultLanguage] = useState<string>('eng') | ||
const [modules, setModules] = useState<ModuleResInterface[]>([]) | ||
|
@@ -15,7 +17,8 @@ export default function Home() { | |
) | ||
const [newsfeedModules, setNewsfeedModules] = useState<NewsInterface[]>([]) | ||
const [errorFlag, setErrorFlag] = useState<boolean>(false) | ||
|
||
const navigate = useNavigate() | ||
//localStorage.getItem(LANGUAGE_LOCAL_STORAGE_KEY),localStorage.getItem(LIFELINES_LOCAL_STORAGE_KEY) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this comment necessary? |
||
useEffect(() => { | ||
getData( | ||
URL, | ||
|
@@ -26,7 +29,9 @@ export default function Home() { | |
setLifelineModules, | ||
setNewsfeedModules, | ||
) | ||
}, [defaultLanguage]) | ||
UpdateURL(navigate, defaultLanguage, lifelineModules) | ||
UpdateSettings(defaultLanguage, lifelineModules) | ||
}, [navigate, defaultLanguage, lifelineModules]) | ||
|
||
return ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { decompressFromEncodedURIComponent } from 'lz-string' | ||
import { COMPRESSED_KEY } from '../utils/constants' | ||
export const UpdateSettings = (selectLanguage, lifelineModules) => { | ||
let decompressed = JSON.parse( | ||
decompressFromEncodedURIComponent(localStorage.getItem(COMPRESSED_KEY)), | ||
) | ||
if (decompressed.language !== selectLanguage) { | ||
selectLanguage = decompressed.language | ||
} | ||
if (lifelineModules != null && decompressed.lifelines !== lifelineModules) { | ||
lifelineModules = decompressed.lifelines | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
COMPRESSED_KEY, | ||
LANGUAGE_LOCAL_STORAGE_KEY, | ||
LIFELINES_LOCAL_STORAGE_KEY, | ||
} from '../utils/constants' | ||
export const UpdateURL = (navigate, language, lifelines) => { | ||
if ( | ||
language && | ||
localStorage.getItem(LANGUAGE_LOCAL_STORAGE_KEY) !== language | ||
) { | ||
navigate(`${localStorage.getItem(COMPRESSED_KEY)}`) | ||
} | ||
if ( | ||
lifelines && | ||
localStorage.getItem(LIFELINES_LOCAL_STORAGE_KEY) !== lifelines | ||
) { | ||
navigate(`${localStorage.getItem(COMPRESSED_KEY)}`) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment necessary?