-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ba68ab8
commit d013255
Showing
5 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { useLocation } from '@gatsbyjs/reach-router'; | ||
import { UnifiedFooter } from '@mdb/consistent-nav'; | ||
import { AVAILABLE_LANGUAGES, getCurrLocale, onSelectLocale } from '../utils/locale'; | ||
import { isBrowser } from '../utils/is-browser'; | ||
import { AVAILABLE_LANGUAGES, STORAGE_KEY_PREF_LOCALE, getCurrLocale, localizePath } from '../utils/locale'; | ||
import { setLocalValue } from '../utils/browser-storage'; | ||
|
||
const Footer = () => { | ||
const enabledLocales = AVAILABLE_LANGUAGES.map((language) => language.localeCode); | ||
return <UnifiedFooter onSelectLocale={onSelectLocale} locale={getCurrLocale()} enabledLocales={enabledLocales} />; | ||
const location = useLocation(); | ||
|
||
const onSelectLocale = (locale) => { | ||
if (isBrowser) { | ||
setLocalValue(STORAGE_KEY_PREF_LOCALE, locale); | ||
const localizedPath = localizePath(location.pathname, locale); | ||
window.location.href = localizedPath; | ||
} | ||
}; | ||
|
||
// A workaround to remove the other locale options | ||
useEffect(() => { | ||
const footer = document.getElementById('footer-container'); | ||
const footerUlElement = footer?.querySelector('ul[role=listbox]'); | ||
if (footerUlElement) { | ||
// For DOP-4296 we only want to support English, Simple Chinese, Korean, and Portuguese. | ||
const availableOptions = Array.from(footerUlElement.childNodes).reduce((accumulator, child) => { | ||
if (AVAILABLE_LANGUAGES.find(({ language }) => child.textContent === language)) { | ||
accumulator.push(child); | ||
} | ||
return accumulator; | ||
}, []); | ||
|
||
footerUlElement.innerHTML = null; | ||
availableOptions.forEach((child) => { | ||
footerUlElement.appendChild(child); | ||
}); | ||
} | ||
}, []); | ||
|
||
return <UnifiedFooter onSelectLocale={onSelectLocale} locale={getCurrLocale()} />; | ||
}; | ||
|
||
export default Footer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters