Fixed ISO-8859 bug

This commit is contained in:
dbroqua 2020-03-01 21:17:51 +01:00
parent b481f4c4d7
commit f73a9e8e36
5 changed files with 27 additions and 5 deletions

View file

@ -9,6 +9,7 @@
"bootstrap": "^4.4.1",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"iconv-lite": "^0.5.1",
"mapbox-gl": "^1.8.1",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
@ -64,4 +65,4 @@
"husky": "^4.2.3",
"lint-staged": "^10.0.8"
}
}
}

View file

@ -2,6 +2,8 @@ import React from 'react';
import { Modal, Button, ListGroup } from "react-bootstrap";
import PropTypes from 'prop-types';
import { capitalizeFirstLetter} from "../helpers";
class GasStation extends React.Component {
renderPrices = () => {
const {
@ -38,7 +40,7 @@ class GasStation extends React.Component {
>
<Modal.Header closeButton>
<Modal.Title>
{`${selectedGasStation.address} - ${selectedGasStation.city}`}
{`${selectedGasStation.address} - ${capitalizeFirstLetter(selectedGasStation.city)}`}
</Modal.Title>
</Modal.Header>
<Modal.Body>

View file

@ -4,6 +4,7 @@ import { Button } from "react-bootstrap";
import XmlReader from 'xml-reader';
import { withToastManager } from 'react-toast-notifications';
import PropTypes from 'prop-types';
import iconv from "iconv-lite";
import { haveSelectedGas, extractGasStationFromXml } from '../helpers';
import 'mapbox-gl/dist/mapbox-gl.css';
@ -89,8 +90,11 @@ class Map extends React.Component {
toastManager,
} = this.props;
toastManager.add('Chargement de la liste des stations...', { appearance: 'info', autoDismiss: true });
fetch('/gasStations.xml')
.then((response) => response.text())
.then(res => res.arrayBuffer())
.then(arrayBuffer => iconv.decode(Buffer.from(arrayBuffer), 'iso-8859-1').toString())
.then((response) => {
const reader = XmlReader.create();
@ -110,6 +114,8 @@ class Map extends React.Component {
}));
});
reader.parse(response);
toastManager.add('Liste des stations correctement chargée', { appearance: 'success', autoDismiss: true });
}).catch(() => {
toastManager.add('Erreur lors du chargement de la liste des stations', { appearance: 'error', autoDismiss: true });
});

View file

@ -25,7 +25,7 @@ export const getPlvInformation = (pdv, name) => {
if (currentChildren.type === 'element' && currentChildren.name === name) {
if ( currentChildren.children && currentChildren.children.length > 0 ) {
return currentChildren.children[0].value;
return currentChildren.children[0].value.toLowerCase();
}
return null;
@ -60,4 +60,10 @@ export const extractGasStationFromXml = (currentPdv ) => {
city: getPlvInformation(currentPdv, 'ville')
}
}
export const capitalizeFirstLetter = (string) => {
if ( !string){
return '';
}
return string.charAt(0).toUpperCase() + string.slice(1);
}

View file

@ -5428,6 +5428,13 @@ iconv-lite@0.4.24, iconv-lite@^0.4.24:
dependencies:
safer-buffer ">= 2.1.2 < 3"
iconv-lite@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.5.1.tgz#b2425d3c7b18f7219f2ca663d103bddb91718d64"
integrity sha512-ONHr16SQvKZNSqjQT9gy5z24Jw+uqfO02/ngBSBoqChZ+W8qXX7GPRa1RoUnzGADw8K63R1BXUMzarCVQBpY8Q==
dependencies:
safer-buffer ">= 2.1.2 < 3"
icss-utils@^4.0.0, icss-utils@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-4.1.1.tgz#21170b53789ee27447c2f47dd683081403f9a467"