Skip to content
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

feat(check-language): add info bubble and store language in localStorage #526

Merged
merged 6 commits into from
Aug 27, 2020

Conversation

KatvonRivia
Copy link
Member

@KatvonRivia KatvonRivia commented Aug 25, 2020

closes #466


const getLanguage = () => {
if (localStorage.getItem('language')) {
return localStorage.getItem('language') as Language;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already retrieve the browser language in the language reducer. This would be a good place to also check for the localStorage language. It also has the benefit that it is only evaluated once on app start and not on every render like here.

Also we have to check if the language in the storage is actually one of the available languages similar to the getBrowserLanguage function.

const setLanguage = (language: Language) => {
localStorage.setItem('language', language);

if (localStorage.getItem('language')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this check for? if you set the item first and then check if it's there it should be always true


const Navigation: FunctionComponent = () => {
const dispatch = useDispatch();
const [showMenu, setShowMenu] = useState(false);
const [showInfoBubble, setshowInfoBubble] = useState(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to show the bubble if there is already a language in local storage right?
Something like that?

const savedLanguage = localStorage.getItem('language');
const [showInfoBubble, setshowInfoBubble] = useState(!Boolean(savedLanguage));

@@ -21,6 +21,14 @@ const LanguageSelector: FunctionComponent<Props> = ({className = ''}) => {
const selectedLanguage = useSelector(languageSelector);
const dispatch = useDispatch();

const setLanguage = (language: Language) => {
localStorage.setItem('language', language);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cool if the saving to localStorage and the dispatch would be combined so that we don't have to handle the saving manually in multiple places. We could just always save the language to local storage when dispatching the setLanguageAction action in the actions/set-language.ts file

@KatvonRivia KatvonRivia marked this pull request as ready for review August 26, 2020 10:37
@@ -78,5 +78,6 @@ export default {
'http://twitter.com/intent/tweet?text=ESA%20Climate%20From%20Space&url={currentUrl}'
},
legendImage: `${baseUrlStorage}/legend-images/{variable}.png`,
downloadUrls
downloadUrls,
localStorageLanguage: 'language'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the key and not the language itself. Please name it 'localStorageLanguageKey'

}
return language;
};
localStorage.clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this? Debugging I guess, please remove.

storedLanguage &&
languages.find(
language =>
language.substr(0, 2).toLowerCase() ===
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the substr stuff here. Unlike in the getBrowserLanguage function the language in the localStorage should match the defined languages exactly.

@KatvonRivia KatvonRivia merged commit ea694d8 into develop Aug 27, 2020
@KatvonRivia KatvonRivia deleted the feat/check-language branch August 27, 2020 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chore: on initial load check langauge
2 participants