Fixed some Flow errors

This commit is contained in:
keplyx 2020-02-23 18:15:30 +01:00
parent aefbdba42a
commit d9c07f5df0
12 changed files with 115 additions and 86 deletions

View file

@ -45,12 +45,14 @@ export default class BaseContainer extends React.Component<Props, State> {
isHeaderVisible: true,
};
onDrawerPress: Function;
constructor() {
super();
this.toggle = this.toggle.bind(this);
this.onDrawerPress = this.onDrawerPress.bind(this);
}
toggle() {
onDrawerPress() {
this.props.navigation.toggleDrawer();
}
@ -111,7 +113,7 @@ export default class BaseContainer extends React.Component<Props, State> {
leftButton={
<Touchable
style={{padding: 6}}
onPress={this.toggle}>
onPress={this.onDrawerPress}>
<CustomMaterialIcon
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
icon="menu"/>

View file

@ -44,6 +44,8 @@ export default class CustomHeader extends React.Component<Props> {
hasTabs: false,
};
onPressBack: Function;
constructor() {
super();
this.onPressBack = this.onPressBack.bind(this);
@ -80,7 +82,7 @@ export default class CustomHeader extends React.Component<Props> {
color={ThemeManager.getCurrentThemeVariables().toolbarBtnColor}/>
<Input
ref="searchInput"
placeholder={i18n.t('proximoScreen.search')}
placeholder={i18n.t('proximoScreen.onSearchStringChange')}
placeholderTextColor={ThemeManager.getCurrentThemeVariables().toolbarPlaceholderColor}
onChangeText={this.props.searchCallback}/>
</Item>

View file

@ -41,12 +41,18 @@ export default class FetchedDataSectionList extends React.Component<Props, State
machinesWatched: [],
};
onRefresh: Function;
renderSectionHeaderEmpty: Function;
renderSectionHeaderNotEmpty: Function;
renderItemEmpty: Function;
renderItemNotEmpty: Function;
constructor(fetchUrl: string, refreshTime: number) {
super();
this.webDataManager = new WebDataManager(fetchUrl);
this.refreshTime = refreshTime;
// creating references to functions used in render()
this._onRefresh = this._onRefresh.bind(this);
this.onRefresh = this.onRefresh.bind(this);
this.renderSectionHeaderEmpty = this.renderSectionHeader.bind(this, true);
this.renderSectionHeaderNotEmpty = this.renderSectionHeader.bind(this, false);
this.renderItemEmpty = this.renderItem.bind(this, true);
@ -96,9 +102,9 @@ export default class FetchedDataSectionList extends React.Component<Props, State
* Refresh data when focusing the screen and setup a refresh interval if asked to
*/
onScreenFocus() {
this._onRefresh();
this.onRefresh();
if (this.refreshTime > 0)
this.refreshInterval = setInterval(this._onRefresh.bind(this), this.refreshTime)
this.refreshInterval = setInterval(this.onRefresh.bind(this), this.refreshTime)
}
/**
@ -122,7 +128,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
* Refresh data and show a toast if any error occurred
* @private
*/
_onRefresh() {
onRefresh() {
let canRefresh;
if (this.lastRefresh !== undefined)
canRefresh = (new Date().getTime() - this.lastRefresh.getTime()) / 1000 > this.minTimeBetweenRefresh;
@ -284,13 +290,13 @@ export default class FetchedDataSectionList extends React.Component<Props, State
}
renderSectionHeader(isEmpty, {section: {title}}) {
renderSectionHeader(isEmpty: boolean, {section: {title}} : Object) {
return isEmpty ?
<View/> :
this.getRenderSectionHeader(title)
}
renderItem(isEmpty, {item, section}) {
renderItem(isEmpty: boolean, {item, section}: Object) {
return isEmpty ?
this.getEmptyRenderItem(item.text, item.isSpinner, item.icon) :
this.getRenderItem(item, section)
@ -313,7 +319,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh}
onRefresh={this.onRefresh}
/>
}
renderSectionHeader={isEmpty ? this.renderSectionHeaderEmpty : this.renderSectionHeaderNotEmpty}

View file

@ -30,6 +30,8 @@ export default class SideBar extends React.Component<Props, State> {
active: 'Home',
};
getRenderItem: Function;
/**
* Generate the datasets
*
@ -111,7 +113,7 @@ export default class SideBar extends React.Component<Props, State> {
}
onListItemPress(item) {
onListItemPress(item: Object) {
if (item.link !== undefined)
Linking.openURL(item.link).catch((err) => console.error('Error opening link', err));
else
@ -119,7 +121,7 @@ export default class SideBar extends React.Component<Props, State> {
}
listKeyExtractor(item) {
listKeyExtractor(item: Object) {
return item.route;
}

View file

@ -210,7 +210,7 @@ export default class AboutScreen extends React.Component<Props, State> {
data={this.appData}
extraData={this.state}
keyExtractor={(item) => item.icon}
listKey={(item) => "app"}
listKey={"app"}
renderItem={({item}) =>
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}
@ -241,7 +241,7 @@ export default class AboutScreen extends React.Component<Props, State> {
data={this.authorData}
extraData={this.state}
keyExtractor={(item) => item.icon}
listKey={(item) => "team1"}
listKey={"team1"}
renderItem={({item}) =>
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}
@ -253,7 +253,7 @@ export default class AboutScreen extends React.Component<Props, State> {
data={this.additionalDevData}
extraData={this.state}
keyExtractor={(item) => item.icon}
listKey={(item) => "team2"}
listKey={"team2"}
renderItem={({item}) =>
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}
@ -272,7 +272,7 @@ export default class AboutScreen extends React.Component<Props, State> {
data={this.technoData}
extraData={this.state}
keyExtractor={(item) => item.icon}
listKey={(item) => "techno"}
listKey={"techno"}
renderItem={({item}) =>
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}

View file

@ -38,12 +38,33 @@ function openWebLink(link) {
*/
export default class HomeScreen extends FetchedDataSectionList {
onProxiwashClick: Function;
onTutorInsaClick: Function;
onMenuClick: Function;
onProximoClick: Function;
constructor() {
super(DATA_URL, REFRESH_TIME);
this.proxiwashClickAction = this.proxiwashClickAction.bind(this);
this.tutorinsaClickAction = this.tutorinsaClickAction.bind(this);
this.menuClickAction = this.menuClickAction.bind(this);
this.proximoClickAction = this.proximoClickAction.bind(this);
this.onProxiwashClick = this.onProxiwashClick.bind(this);
this.onTutorInsaClick = this.onTutorInsaClick.bind(this);
this.onMenuClick = this.onMenuClick.bind(this);
this.onProximoClick = this.onProximoClick.bind(this);
}
onProxiwashClick() {
this.props.navigation.navigate('Proxiwash');
}
onTutorInsaClick() {
this.props.navigation.navigate('TutorInsaScreen');
}
onProximoClick() {
this.props.navigation.navigate('Proximo');
}
onMenuClick() {
this.props.navigation.navigate('SelfMenuScreen');
}
/**
@ -293,7 +314,7 @@ export default class HomeScreen extends FetchedDataSectionList {
}
clickAction(isAvailable, displayEvent) {
clickAction(isAvailable: boolean, displayEvent: Object) {
if (isAvailable)
this.props.navigation.navigate('PlanningDisplayScreen', {data: displayEvent});
else
@ -338,14 +359,6 @@ export default class HomeScreen extends FetchedDataSectionList {
);
}
proximoClickAction() {
this.props.navigation.navigate('Proximo');
}
menuClickAction() {
this.props.navigation.navigate('SelfMenuScreen');
}
getDashboardBottomItem(content: Array<Object>) {
let proximoData = content[0]['data'];
@ -391,7 +404,7 @@ export default class HomeScreen extends FetchedDataSectionList {
subtitle={menuSubtitle}
color={menuColor}
icon={menuIcon}
clickAction={this.menuClickAction}
clickAction={this.onMenuClick}
title={menuTitle}
isAvailable={isMenuAvailable}
isSquareLeft={true}/>
@ -400,21 +413,13 @@ export default class HomeScreen extends FetchedDataSectionList {
subtitle={proximoSubtitle}
color={proximoColor}
icon={proximoIcon}
clickAction={this.proximoClickAction}
clickAction={this.onProximoClick}
title={proximoTitle}
isAvailable={isProximoAvailable}/>
</View>
);
}
proxiwashClickAction() {
this.props.navigation.navigate('Proxiwash');
}
tutorinsaClickAction() {
this.props.navigation.navigate('TutorInsaScreen');
}
getDashboardMiddleItem(content: Array<Object>) {
let proxiwashData = content[0]['data'];
@ -502,7 +507,7 @@ export default class HomeScreen extends FetchedDataSectionList {
subtitle={proxiwashSubtitle}
color={proxiwashColor}
icon={proxiwashIcon}
clickAction={this.proxiwashClickAction}
clickAction={this.onProxiwashClick}
title={proxiwashTitle}
isAvailable={proxiwashIsAvailable}
isSquareLeft={true}/>
@ -511,7 +516,7 @@ export default class HomeScreen extends FetchedDataSectionList {
subtitle={tutorinsaSubtitle}
color={tutorinsaColor}
icon={tutorinsaIcon}
clickAction={this.tutorinsaClickAction}
clickAction={this.onTutorInsaClick}
title={tutorinsaTitle}
isAvailable={tutorinsaIsAvailable}/>
</View>

View file

@ -8,7 +8,6 @@ import ThemeManager from "../utils/ThemeManager";
import HTML from "react-native-render-html";
import {Linking} from "expo";
import PlanningEventManager from '../utils/PlanningEventManager';
import i18n from 'i18n-js';
type Props = {
navigation: Object,

View file

@ -5,7 +5,6 @@ import {BackHandler, Image} from 'react-native';
import {H3, Text, View} from 'native-base';
import i18n from "i18n-js";
import ThemeManager from "../utils/ThemeManager";
import {Linking} from "expo";
import BaseContainer from "../components/BaseContainer";
import {Agenda, LocaleConfig} from 'react-native-calendars';
import Touchable from 'react-native-platform-touchable';
@ -35,14 +34,6 @@ const FETCH_URL = "https://amicale-insat.fr/event/json/list";
const AGENDA_MONTH_SPAN = 6;
/**
* Opens a link in the device's browser
* @param link The link to open
*/
function openWebLink(link) {
Linking.openURL(link).catch((err) => console.error('Error opening link', err));
}
/**
* Class defining the app's planning screen
*/
@ -63,6 +54,14 @@ export default class PlanningScreen extends React.Component<Props, State> {
calendarShowing: false,
};
onRefresh: Function;
onCalendarToggled: Function;
getRenderItem: Function;
getRenderEmptyDate: Function;
onAgendaRef: Function;
onCalendarToggled: Function;
onBackButtonPressAndroid: Function;
constructor(props: any) {
super(props);
this.webDataManager = new WebDataManager(FETCH_URL);
@ -79,12 +78,11 @@ export default class PlanningScreen extends React.Component<Props, State> {
}
// Create references for functions required in the render function
this._onRefresh = this._onRefresh.bind(this);
this.onRefresh = this.onRefresh.bind(this);
this.onCalendarToggled = this.onCalendarToggled.bind(this);
this.getRenderItem = this.getRenderItem.bind(this);
this.getRenderEmptyDate = this.getRenderEmptyDate.bind(this);
this.setAgendaRef = this.setAgendaRef.bind(this);
this.onCalendarToggled = this.onCalendarToggled.bind(this);
this.onAgendaRef = this.onAgendaRef.bind(this);
this.onCalendarToggled = this.onCalendarToggled.bind(this);
this.onBackButtonPressAndroid = this.onBackButtonPressAndroid.bind(this);
}
@ -96,7 +94,7 @@ export default class PlanningScreen extends React.Component<Props, State> {
}
componentDidMount() {
this._onRefresh();
this.onRefresh();
this.willBlurSubscription = this.props.navigation.addListener(
'willBlur',
() =>
@ -213,7 +211,7 @@ export default class PlanningScreen extends React.Component<Props, State> {
* Refresh data and show a toast if any error occurred
* @private
*/
_onRefresh = () => {
onRefresh = () => {
let canRefresh;
if (this.lastRefresh !== undefined)
canRefresh = (new Date().getTime() - this.lastRefresh.getTime()) / 1000 > this.minTimeBetweenRefresh;
@ -265,12 +263,12 @@ export default class PlanningScreen extends React.Component<Props, State> {
}
}
setAgendaRef(ref) {
onAgendaRef(ref: Agenda) {
this.agendaRef = ref;
}
onCalendarToggled(calendarOpened) {
this.setState({calendarShowing: calendarOpened});
onCalendarToggled(isCalendarOpened: boolean) {
this.setState({calendarShowing: isCalendarOpened});
}
currentDate = this.getCurrentDate();
@ -293,7 +291,7 @@ export default class PlanningScreen extends React.Component<Props, State> {
// Max amount of months allowed to scroll to the future. Default = 50
futureScrollRange={AGENDA_MONTH_SPAN}
// If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly.
onRefresh={this._onRefresh}
onRefresh={this.onRefresh}
// callback that fires when the calendar is opened or closed
onCalendarToggled={this.onCalendarToggled}
// Set this true while waiting for new data from a refresh
@ -304,7 +302,7 @@ export default class PlanningScreen extends React.Component<Props, State> {
// If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday.
firstDay={1}
// ref to this agenda in order to handle back button event
ref={this.setAgendaRef}
ref={this.onAgendaRef}
// agenda theme
theme={{
backgroundColor: ThemeManager.getCurrentThemeVariables().agendaBackgroundColor,

View file

@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import {Image, Linking, View} from 'react-native';
import {Image, View} from 'react-native';
import {Card, CardItem, Container, Content, H2, Left, Text} from 'native-base';
import CustomHeader from "../../components/CustomHeader";
import i18n from "i18n-js";

View file

@ -70,16 +70,25 @@ export default class ProximoListScreen extends React.Component<Props, State> {
sortNameIcon: '',
modalCurrentDisplayItem: {},
};
_menu: Menu;
sortMenuRef: Menu;
onMenuRef: Function;
onSearchStringChange: Function;
onSelectSortModeName: Function;
onSelectSortModePrice: Function;
onSortMenuPress: Function;
renderItem: Function;
constructor(props: any) {
super(props);
this.modalRef = React.createRef();
this.originalData = this.navData['data'];
this.search = this.search.bind(this);
this.selectSortModeName = this.selectSortModeName.bind(this);
this.selectSortModePrice = this.selectSortModePrice.bind(this);
this.showMenu = this.showMenu.bind(this);
this.onMenuRef = this.onMenuRef.bind(this);
this.onSearchStringChange = this.onSearchStringChange.bind(this);
this.onSelectSortModeName = this.onSelectSortModeName.bind(this);
this.onSelectSortModePrice = this.onSelectSortModePrice.bind(this);
this.onSortMenuPress = this.onSortMenuPress.bind(this);
this.renderItem = this.renderItem.bind(this);
}
@ -88,8 +97,8 @@ export default class ProximoListScreen extends React.Component<Props, State> {
*
* @param ref The menu reference
*/
setMenuRef = (ref: Menu) => {
this._menu = ref;
onMenuRef(ref: Menu) {
this.sortMenuRef = ref;
};
/**
@ -136,7 +145,7 @@ export default class ProximoListScreen extends React.Component<Props, State> {
break;
}
this.setupSortIcons(mode, isReverse);
this._menu.hide();
this.sortMenuRef.hide();
}
/**
@ -219,7 +228,7 @@ export default class ProximoListScreen extends React.Component<Props, State> {
return filteredData;
}
search(str: string) {
onSearchStringChange(str: string) {
this.setState({
currentlyDisplayedData: this.filterData(str)
})
@ -265,27 +274,27 @@ export default class ProximoListScreen extends React.Component<Props, State> {
}
}
selectSortModeName() {
onSelectSortModeName() {
this.sortModeSelected(sortMode.name);
}
selectSortModePrice() {
onSelectSortModePrice() {
this.sortModeSelected(sortMode.price);
}
showMenu() {
this._menu.show();
onSortMenuPress() {
this.sortMenuRef.show();
}
getSortMenu() {
return (
<Menu
ref={this.setMenuRef}
ref={this.onMenuRef}
button={
<Touchable
style={{padding: 6}}
onPress={this.showMenu}>
onPress={this.onSortMenuPress}>
<CustomMaterialIcon
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
icon={'sort'}/>
@ -293,12 +302,12 @@ export default class ProximoListScreen extends React.Component<Props, State> {
}
>
<MenuItem
onPress={this.selectSortModeName}>
onPress={this.onSelectSortModeName}>
{this.state.sortNameIcon}
{i18n.t('proximoScreen.sortName')}
</MenuItem>
<MenuItem
onPress={this.selectSortModePrice}>
onPress={this.onSelectSortModePrice}>
{this.state.sortPriceIcon}
{i18n.t('proximoScreen.sortPrice')}
</MenuItem>
@ -306,7 +315,8 @@ export default class ProximoListScreen extends React.Component<Props, State> {
);
}
renderItem({item}) {
renderItem({item}: Object) {
console.log(item);
return (<ListItem
thumbnail
onPress={() => {
@ -335,7 +345,7 @@ export default class ProximoListScreen extends React.Component<Props, State> {
</ListItem>);
}
keyExtractor(item) {
keyExtractor(item: Object) {
return item.name + item.code;
}
@ -353,7 +363,7 @@ export default class ProximoListScreen extends React.Component<Props, State> {
hasBackButton={true}
navigation={nav}
hasSearchField={true}
searchCallback={this.search}
searchCallback={this.onSearchStringChange}
shouldFocusSearchBar={this.shouldFocusSearchBar}
rightButton={this.getSortMenu()}
/>

View file

@ -18,6 +18,9 @@ const DATA_URL = "https://srv-falcon.etud.insa-toulouse.fr/~proximo/data/stock-v
*/
export default class ProximoMainScreen extends FetchedDataSectionList {
onPressSearchBtn: Function;
onPressAboutBtn: Function;
constructor() {
super(DATA_URL, 0);
this.onPressSearchBtn = this.onPressSearchBtn.bind(this);

View file

@ -36,6 +36,8 @@ const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
*/
export default class ProxiwashScreen extends FetchedDataSectionList {
onAboutPress: Function;
/**
* Creates machine state parameters using current theme and translations
*/
@ -76,7 +78,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
};
this.setMinTimeRefresh(30);
this.navigateToAboutScreen = this.navigateToAboutScreen.bind(this);
this.onAboutPress = this.onAboutPress.bind(this);
}
/**
@ -274,7 +276,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
);
}
navigateToAboutScreen() {
onAboutPress() {
this.props.navigation.navigate('ProxiwashAboutScreen');
}
@ -282,7 +284,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
return (
<Touchable
style={{padding: 6}}
onPress={this.navigateToAboutScreen}>
onPress={this.onAboutPress}>
<CustomMaterialIcon
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
icon="information"/>