🐛 répare la page blanche en cas de blocage des cookie par l'utilisateur

pull/536/head
Johan Girod 2019-05-14 13:34:48 +02:00
parent 4cf4318df5
commit c4119fc509
No known key found for this signature in database
GPG Key ID: 9E27B57DA2E8AE12
3 changed files with 19 additions and 15 deletions

View File

@ -2,16 +2,12 @@ import i18next from 'i18next'
import queryString from 'query-string'
import { initReactI18next } from 'react-i18next'
import enTranslations from './locales/en.yaml'
import { getIframeOption, parseDataAttributes } from './utils'
let getFromSessionStorage = where =>
typeof sessionStorage !== 'undefined' ? sessionStorage[where] : null
let setToSessionStorage = (where, what) =>
typeof sessionStorage !== 'undefined' &&
do {
sessionStorage[where] = what
}
import {
getFromSessionStorage,
getIframeOption,
parseDataAttributes,
setToSessionStorage
} from './utils'
let lang =
getIframeOption('lang') ||

View File

@ -21,7 +21,7 @@ import {
retrievePersistedSimulation
} from '../../storage/persistSimulation'
import ReactPiwik from '../../Tracker'
import { inIframe } from '../../utils'
import { inIframe, setToSessionStorage } from '../../utils'
import './App.css'
import Footer from './layout/Footer/Footer'
import Header from './layout/Header/Header'
@ -60,9 +60,7 @@ const middlewares = [
class InFranceRoute extends Component {
componentDidMount() {
if (typeof sessionStorage !== 'undefined') {
sessionStorage['lang'] = this.props.language
}
setToSessionStorage('lang', this.props.language)
}
render() {
const paths = constructLocalizedSitePath(this.props.language)

View File

@ -66,7 +66,7 @@ export function inIframe() {
}
}
export function softCatch<ArgType: any, ReturnType: any>(
export function softCatch<ArgType: mixed, ReturnType: mixed>(
fn: ArgType => ReturnType
): ArgType => ReturnType | null {
return function(...args) {
@ -102,3 +102,13 @@ export const constructSitePaths = (
sitePaths
)
})
export const getFromSessionStorage = softCatch<string, any>(where => {
typeof sessionStorage !== 'undefined' ? sessionStorage[where] : null
})
export const setToSessionStorage = softCatch<string, void>((where, what) => {
if (typeof sessionStorage !== 'undefined') {
sessionStorage[where] = what
}
})