🔥 Supprime des fonctions "utils" inutiles
Ces fonctions n'étaient utilisées qu'une fois ou deux et constituent des indirections inutiles : getIframeOption, parseDataAttributes, setToSessionStorage, getFromSessionStorage et isNumeric. Préférer les fonctions de la "bibliothèque standard": sessionStorage et URLSearchParams.pull/719/head
parent
7a9f2d606f
commit
41e44482b8
|
@ -10,7 +10,7 @@ import { Router } from 'react-router-dom'
|
|||
import reducers from 'Reducers/rootReducer'
|
||||
import { applyMiddleware, compose, createStore } from 'redux'
|
||||
import thunk from 'redux-thunk'
|
||||
import { getIframeOption, inIframe } from './utils'
|
||||
import { inIframe } from './utils'
|
||||
|
||||
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
|
||||
|
||||
|
@ -73,10 +73,13 @@ export default class Provider extends PureComponent {
|
|||
this.props.tracker.disconnectFromHistory()
|
||||
}
|
||||
render() {
|
||||
const iframeCouleur = new URLSearchParams(
|
||||
document.location.search.substring(1)
|
||||
).get('couleur')
|
||||
return (
|
||||
// If IE < 11 display nothing
|
||||
<ReduxProvider store={this.store}>
|
||||
<ThemeColoursProvider colour={getIframeOption('couleur')}>
|
||||
<ThemeColoursProvider colour={iframeCouleur}>
|
||||
<TrackerProvider value={this.props.tracker}>
|
||||
<SitePathProvider value={this.props.sitePaths}>
|
||||
<I18nextProvider i18n={i18next}>
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
import i18next from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
import enTranslations from './locales/en.yaml'
|
||||
import {
|
||||
getFromSessionStorage,
|
||||
getIframeOption,
|
||||
parseDataAttributes,
|
||||
setToSessionStorage
|
||||
} from './utils'
|
||||
|
||||
let lang =
|
||||
getIframeOption('lang') ||
|
||||
new URLSearchParams(document.location.search.substring(1)).get('lang') ||
|
||||
parseDataAttributes(getFromSessionStorage('lang')) ||
|
||||
sessionStorage?.getItem('lang')?.match(/^(fr|en)$/)?.[0] ||
|
||||
'fr'
|
||||
|
||||
setToSessionStorage('lang', lang)
|
||||
sessionStorage?.setItem('lang', lang)
|
||||
i18next
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
retrievePersistedSimulation
|
||||
} from '../../storage/persistSimulation'
|
||||
import Tracker, { devTracker } from '../../Tracker'
|
||||
import { inIframe, setToSessionStorage } from '../../utils'
|
||||
import { inIframe } from '../../utils'
|
||||
import './App.css'
|
||||
import Footer from './layout/Footer/Footer'
|
||||
import { PrivacyContent } from './layout/Footer/Privacy'
|
||||
|
@ -59,7 +59,7 @@ const middlewares = [
|
|||
|
||||
function InFranceRoute({ basename, language }) {
|
||||
useEffect(() => {
|
||||
setToSessionStorage('lang', language)
|
||||
sessionStorage?.setItem('lang', language)
|
||||
}, [language])
|
||||
const paths = constructLocalizedSitePath(language)
|
||||
const rules = language === 'en' ? baseRulesEn : baseRulesFr
|
||||
|
|
|
@ -4,31 +4,6 @@ import { map } from 'ramda'
|
|||
export let capitalise0 = (name: string) =>
|
||||
name && name[0].toUpperCase() + name.slice(1)
|
||||
|
||||
export let getUrl = () =>
|
||||
typeof window !== 'undefined' ? window.location.href.toString() : null
|
||||
|
||||
export let parseDataAttributes = (value: any) =>
|
||||
value === 'undefined'
|
||||
? undefined
|
||||
: value === null
|
||||
? null
|
||||
: !isNaN(value)
|
||||
? +value
|
||||
: /* value is a normal string */
|
||||
value
|
||||
|
||||
export let getIframeOption = (optionName: string) => {
|
||||
let url = getUrl(),
|
||||
hasOption = url?.includes(optionName + '=')
|
||||
return parseDataAttributes(
|
||||
hasOption && url.split(optionName + '=')[1].split('&')[0]
|
||||
)
|
||||
}
|
||||
|
||||
export function isNumeric(val: number) {
|
||||
return Number(parseFloat(val)) === val
|
||||
}
|
||||
|
||||
export function debounce<ArgType: any>(
|
||||
timeout: number,
|
||||
fn: ArgType => void
|
||||
|
@ -94,13 +69,3 @@ 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
|
||||
}
|
||||
})
|
||||
|
|
|
@ -10,7 +10,6 @@ import { analyse, parseAll } from '../source/engine/traverse'
|
|||
import { collectMissingVariables } from '../source/engine/generateQuestions'
|
||||
import testSuites from './load-mecanism-tests'
|
||||
import * as R from 'ramda'
|
||||
import { isNumeric } from '../source/utils'
|
||||
import { serialiseUnit } from 'Engine/units'
|
||||
|
||||
describe('Mécanismes', () =>
|
||||
|
@ -43,7 +42,7 @@ describe('Mécanismes', () =>
|
|||
missing = collectMissingVariables(analysis.targets),
|
||||
target = analysis.targets[0]
|
||||
|
||||
if (isNumeric(valeur)) {
|
||||
if (typeof valeur === 'number') {
|
||||
expect(target.nodeValue).to.be.closeTo(valeur, 0.001)
|
||||
} else if (valeur !== undefined) {
|
||||
expect(target).to.have.property('nodeValue', valeur)
|
||||
|
|
Loading…
Reference in New Issue