// @flow
import * as React from 'react';
import {Badge, Body, H2, Left, ListItem, Right, Text} from 'native-base';
import i18n from "i18n-js";
import CustomMaterialIcon from "../../components/CustomMaterialIcon";
import FetchedDataSectionList from "../../components/FetchedDataSectionList";
const DATA_URL = "https://etud.insa-toulouse.fr/~vergnet/appli-amicale/dataProximo.json";
const typesIcons = {
Nouveau: "alert-decagram",
Alimentaire: "food",
Boissons: "bottle-wine",
Utilitaires: "notebook",
Default: "information-outline",
};
/**
* Class defining the main proximo screen. This screen shows the different categories of articles
* offered by proximo.
*/
export default class ProximoMainScreen extends FetchedDataSectionList {
constructor() {
super(DATA_URL);
}
getHeaderTranslation() {
return i18n.t("screens.proximo");
}
getUpdateToastTranslations() {
return [i18n.t("proximoScreen.listUpdated"), i18n.t("proximoScreen.listUpdateFail")];
}
getKeyExtractor(item: Object) {
return item !== undefined ? item.type : undefined;
}
createDataset(fetchedData: Object) {
return [
{
title: i18n.t('proximoScreen.listTitle'),
data: ProximoMainScreen.generateData(fetchedData),
extraData: super.state,
}
];
}
/**
* Generate the data using types and FetchedData.
* This will group items under the same type.
*
* @param fetchedData The array of articles represented by objects
* @returns {Array} The formatted dataset
*/
static generateData(fetchedData: Object) {
let finalData = [];
if (fetchedData.types !== undefined && fetchedData.articles !== undefined) {
let types = fetchedData.types;
let articles = fetchedData.articles;
for (let i = 0; i < types.length; i++) {
finalData.push({
type: types[i],
data: []
});
for (let k = 0; k < articles.length; k++) {
if (articles[k]['type'].includes(types[i])) {
finalData[i].data.push(articles[k]);
}
}
}
}
return finalData;
}
getRenderItem(item: Object, section : Object, data : Object) {
return (