Changed fb data url to use etud, changed proxiwash display to use a tab system

This commit is contained in:
keplyx 2019-07-28 12:40:35 +02:00
parent d2c3d1908b
commit 5bda2825c5
5 changed files with 83 additions and 39 deletions

View file

@ -11,6 +11,7 @@ type Props = {
rightMenu: React.Node, rightMenu: React.Node,
title: string, title: string,
navigation: Object, navigation: Object,
hasTabs: boolean,
}; };
/** /**
@ -26,6 +27,7 @@ export default class CustomHeader extends React.Component<Props> {
static defaultProps = { static defaultProps = {
backButton: false, backButton: false,
rightMenu: <Right/>, rightMenu: <Right/>,
hasTabs: false,
}; };
render() { render() {

View file

@ -2,9 +2,9 @@
import * as React from 'react'; import * as React from 'react';
import WebDataManager from "../utils/WebDataManager"; import WebDataManager from "../utils/WebDataManager";
import {Container, Content, H2} from "native-base"; import {Container, Content, Tab, TabHeading, Tabs, Text} from "native-base";
import CustomHeader from "./CustomHeader"; import CustomHeader from "./CustomHeader";
import {SectionList, RefreshControl, View} from "react-native"; import {RefreshControl, SectionList, View} from "react-native";
type Props = { type Props = {
navigation: Object, navigation: Object,
@ -14,12 +14,12 @@ type State = {
refreshing: boolean, refreshing: boolean,
firstLoading: boolean, firstLoading: boolean,
fetchedData: Object, fetchedData: Object,
machinesWatched : Array<Object> machinesWatched: Array<Object>
}; };
export default class FetchedDataSectionList extends React.Component<Props, State> { export default class FetchedDataSectionList extends React.Component<Props, State> {
webDataManager : WebDataManager; webDataManager: WebDataManager;
constructor() { constructor() {
super(); super();
@ -30,7 +30,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
refreshing: false, refreshing: false,
firstLoading: true, firstLoading: true,
fetchedData: {}, fetchedData: {},
machinesWatched : [], machinesWatched: [],
}; };
getFetchUrl() { getFetchUrl() {
@ -41,7 +41,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
return "Header"; return "Header";
} }
getUpdateToastTranslations () { getUpdateToastTranslations() {
return ["whoa", "nah"]; return ["whoa", "nah"];
} }
@ -64,12 +64,12 @@ export default class FetchedDataSectionList extends React.Component<Props, State
}); });
}; };
getRenderItem(item: Object, section : Object, data : Object) { getRenderItem(item: Object, section: Object, data: Object) {
return <View />; return <View/>;
} }
getRenderSectionHeader(title: String) { getRenderSectionHeader(title: String) {
return <View />; return <View/>;
} }
/** /**
@ -77,7 +77,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
* @param fetchedData {Object} * @param fetchedData {Object}
* @return {Array} * @return {Array}
*/ */
createDataset(fetchedData : Object) : Array<Object> { createDataset(fetchedData: Object): Array<Object> {
return []; return [];
} }
@ -86,35 +86,72 @@ export default class FetchedDataSectionList extends React.Component<Props, State
* @param item {Object} * @param item {Object}
* @return {*} * @return {*}
*/ */
getKeyExtractor(item : Object) { getKeyExtractor(item: Object) {
return item.id; return item.id;
} }
hasTabs() {
return false;
}
getSectionList(dataset: Array<Object>) {
return (
<SectionList
sections={dataset}
keyExtractor={(item) => this.getKeyExtractor(item)}
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh}
/>
}
renderSectionHeader={({section: {title}}) =>
this.getRenderSectionHeader(title)
}
renderItem={({item, section}) =>
this.getRenderItem(item, section, dataset)
}
style={{minHeight: 300, width: '100%'}}
/>
);
}
getTabbedView(dataset: Array<Object>) {
let tabbedView = [];
for (let i = 0; i < dataset.length; i++) {
tabbedView.push(
<Tab heading={<TabHeading><Text>{dataset[i].title}</Text></TabHeading>}>
<Content padder>
{this.getSectionList(
[
{
title: dataset[i].title,
data: dataset[i].data,
extraData: dataset[i].extraData,
}
]
)}
</Content>
</Tab>);
}
return tabbedView;
}
render() { render() {
const nav = this.props.navigation; const nav = this.props.navigation;
const dataset = this.createDataset(this.state.fetchedData); const dataset = this.createDataset(this.state.fetchedData);
return ( return (
<Container> <Container>
<CustomHeader navigation={nav} title={this.getHeaderTranslation()}/> <CustomHeader navigation={nav} title={this.getHeaderTranslation()}/>
<Content padder> {this.hasTabs() ?
<SectionList <Tabs>
sections={dataset} {this.getTabbedView(dataset)}
keyExtractor={(item) => this.getKeyExtractor(item)} </Tabs>
refreshControl={ :
<RefreshControl <Content padder>
refreshing={this.state.refreshing} {this.getSectionList(dataset)}
onRefresh={this._onRefresh} </Content>
/> }
}
renderSectionHeader={({section: {title}}) =>
this.getRenderSectionHeader(title)
}
renderItem={({item, section}) =>
this.getRenderItem(item, section, dataset)
}
style={{minHeight: 300, width: '100%'}}
/>
</Content>
</Container> </Container>
); );
} }

View file

@ -9,7 +9,8 @@ import FetchedDataSectionList from "../components/FetchedDataSectionList";
const ICON_AMICALE = require('../assets/amicale.png'); const ICON_AMICALE = require('../assets/amicale.png');
const NAME_AMICALE = 'Amicale INSA Toulouse'; const NAME_AMICALE = 'Amicale INSA Toulouse';
const FB_URL = "https://graph.facebook.com/v3.3/amicale.deseleves/posts?fields=message%2Cfull_picture%2Ccreated_time%2Cpermalink_url&&date_format=U&access_token=EAAGliUs4Ei8BAGwHmg7SNnosoEDMuDhP3i5lYOGrIGzZBNeMeGzGhpUigJt167cKXEIM0GiurSgaC0PS4Xg2GBzOVNiZCfr8u48VVB15a9YbOsuhjBqhHAMb2sz6ibwOuDhHSvwRZCUpBZCjmAW12e7RjWJp0jvyNoYYvIQbfaLWi3Nk2mBc"; const FB_URL = "https://etud.insa-toulouse.fr/~vergnet/appli-amicale/facebook_data.json";
/** /**
* Opens a link in the device's browser * Opens a link in the device's browser
@ -33,7 +34,7 @@ export default class HomeScreen extends FetchedDataSectionList {
} }
getKeyExtractor(item : Object) { getKeyExtractor(item : Object) {
return item.id; return item !== undefined ? item.id : undefined;
} }
createDataset(fetchedData : Object) { createDataset(fetchedData : Object) {

View file

@ -36,7 +36,7 @@ export default class ProximoMainScreen extends FetchedDataSectionList {
} }
getKeyExtractor(item: Object) { getKeyExtractor(item: Object) {
return item.type; return item !== undefined ? item.type : undefined;
} }
createDataset(fetchedData: Object) { createDataset(fetchedData: Object) {

View file

@ -78,7 +78,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
} }
getKeyExtractor(item: Object) { getKeyExtractor(item: Object) {
return item.number; return item !== undefined ? item.number : undefined;
} }
/** /**
@ -204,6 +204,10 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
]; ];
} }
hasTabs(): boolean {
return true;
}
/** /**
* Get list item to be rendered * Get list item to be rendered
* *
@ -233,12 +237,12 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
backgroundColor: ThemeManager.getInstance().getCurrentThemeVariables().containerBgColor backgroundColor: ThemeManager.getInstance().getCurrentThemeVariables().containerBgColor
}}/> }}/>
<Left> <Left>
<CustomMaterialIcon icon={section.title === data[0].title ? 'tumble-dryer' : 'washing-machine'} <CustomMaterialIcon icon={section.title === i18n.t('proxiwashScreen.dryers') ? 'tumble-dryer' : 'washing-machine'}
fontSize={30} fontSize={30}
/> />
<Body> <Body>
<Text> <Text>
{section.title === data[0].title ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')} n°{item.number} {section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')} n°{item.number}
</Text> </Text>
<Text note> <Text note>
{item.startTime !== '' ? item.startTime + '/' + item.endTime : ''} {item.startTime !== '' ? item.startTime + '/' + item.endTime : ''}
@ -280,7 +284,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
</Card>); </Card>);
} }
getRenderSectionHeader(title: String) { // getRenderSectionHeader(title: String) {
return <H2 style={{textAlign: 'center', paddingVertical: 10}}>{title}</H2>; // return <H2 style={{textAlign: 'center', paddingVertical: 10}}>{title}</H2>;
} // }
} }