diff --git a/components/BaseContainer.js b/components/BaseContainer.js index 4da6b7e..e712347 100644 --- a/components/BaseContainer.js +++ b/components/BaseContainer.js @@ -45,12 +45,14 @@ export default class BaseContainer extends React.Component { 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 { leftButton={ + onPress={this.onDrawerPress}> diff --git a/components/CustomHeader.js b/components/CustomHeader.js index 8b935fd..cb6bdda 100644 --- a/components/CustomHeader.js +++ b/components/CustomHeader.js @@ -44,6 +44,8 @@ export default class CustomHeader extends React.Component { hasTabs: false, }; + onPressBack: Function; + constructor() { super(); this.onPressBack = this.onPressBack.bind(this); @@ -80,7 +82,7 @@ export default class CustomHeader extends React.Component { color={ThemeManager.getCurrentThemeVariables().toolbarBtnColor}/> diff --git a/components/FetchedDataSectionList.js b/components/FetchedDataSectionList.js index 781f504..75c763c 100644 --- a/components/FetchedDataSectionList.js +++ b/components/FetchedDataSectionList.js @@ -41,12 +41,18 @@ export default class FetchedDataSectionList extends React.Component 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 this.minTimeBetweenRefresh; @@ -284,13 +290,13 @@ export default class FetchedDataSectionList extends React.Component : 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 } renderSectionHeader={isEmpty ? this.renderSectionHeaderEmpty : this.renderSectionHeaderNotEmpty} diff --git a/components/Sidebar.js b/components/Sidebar.js index 61cd73f..5517f99 100644 --- a/components/Sidebar.js +++ b/components/Sidebar.js @@ -30,6 +30,8 @@ export default class SideBar extends React.Component { active: 'Home', }; + getRenderItem: Function; + /** * Generate the datasets * @@ -111,7 +113,7 @@ export default class SideBar extends React.Component { } - 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 { } - listKeyExtractor(item) { + listKeyExtractor(item: Object) { return item.route; } diff --git a/screens/About/AboutScreen.js b/screens/About/AboutScreen.js index c4bc463..14d77a2 100644 --- a/screens/About/AboutScreen.js +++ b/screens/About/AboutScreen.js @@ -210,7 +210,7 @@ export default class AboutScreen extends React.Component { 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 { 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 { 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 { 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) } diff --git a/screens/HomeScreen.js b/screens/HomeScreen.js index dcad00c..4f2207c 100644 --- a/screens/HomeScreen.js +++ b/screens/HomeScreen.js @@ -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) { 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}/> ); } - proxiwashClickAction() { - this.props.navigation.navigate('Proxiwash'); - } - - tutorinsaClickAction() { - this.props.navigation.navigate('TutorInsaScreen'); - } - getDashboardMiddleItem(content: Array) { 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}/> diff --git a/screens/PlanningDisplayScreen.js b/screens/PlanningDisplayScreen.js index 68a02ae..0203f5f 100644 --- a/screens/PlanningDisplayScreen.js +++ b/screens/PlanningDisplayScreen.js @@ -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, diff --git a/screens/PlanningScreen.js b/screens/PlanningScreen.js index b05eeb2..b5aa6a0 100644 --- a/screens/PlanningScreen.js +++ b/screens/PlanningScreen.js @@ -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 { 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 { } // 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 { } componentDidMount() { - this._onRefresh(); + this.onRefresh(); this.willBlurSubscription = this.props.navigation.addListener( 'willBlur', () => @@ -213,7 +211,7 @@ export default class PlanningScreen extends React.Component { * 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 { } } - 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 { // 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 { // 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, diff --git a/screens/Proximo/ProximoAboutScreen.js b/screens/Proximo/ProximoAboutScreen.js index 269a5f6..65a19cf 100644 --- a/screens/Proximo/ProximoAboutScreen.js +++ b/screens/Proximo/ProximoAboutScreen.js @@ -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"; diff --git a/screens/Proximo/ProximoListScreen.js b/screens/Proximo/ProximoListScreen.js index c616381..18f458a 100644 --- a/screens/Proximo/ProximoListScreen.js +++ b/screens/Proximo/ProximoListScreen.js @@ -70,16 +70,25 @@ export default class ProximoListScreen extends React.Component { 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 { * * @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 { break; } this.setupSortIcons(mode, isReverse); - this._menu.hide(); + this.sortMenuRef.hide(); } /** @@ -219,7 +228,7 @@ export default class ProximoListScreen extends React.Component { 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 { } } - selectSortModeName() { + onSelectSortModeName() { this.sortModeSelected(sortMode.name); } - selectSortModePrice() { + onSelectSortModePrice() { this.sortModeSelected(sortMode.price); } - showMenu() { - this._menu.show(); + onSortMenuPress() { + this.sortMenuRef.show(); } getSortMenu() { return ( + onPress={this.onSortMenuPress}> @@ -293,12 +302,12 @@ export default class ProximoListScreen extends React.Component { } > + onPress={this.onSelectSortModeName}> {this.state.sortNameIcon} {i18n.t('proximoScreen.sortName')} + onPress={this.onSelectSortModePrice}> {this.state.sortPriceIcon} {i18n.t('proximoScreen.sortPrice')} @@ -306,7 +315,8 @@ export default class ProximoListScreen extends React.Component { ); } - renderItem({item}) { + renderItem({item}: Object) { + console.log(item); return ( { @@ -335,7 +345,7 @@ export default class ProximoListScreen extends React.Component { ); } - keyExtractor(item) { + keyExtractor(item: Object) { return item.name + item.code; } @@ -353,7 +363,7 @@ export default class ProximoListScreen extends React.Component { hasBackButton={true} navigation={nav} hasSearchField={true} - searchCallback={this.search} + searchCallback={this.onSearchStringChange} shouldFocusSearchBar={this.shouldFocusSearchBar} rightButton={this.getSortMenu()} /> diff --git a/screens/Proximo/ProximoMainScreen.js b/screens/Proximo/ProximoMainScreen.js index 1e030db..932c689 100644 --- a/screens/Proximo/ProximoMainScreen.js +++ b/screens/Proximo/ProximoMainScreen.js @@ -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); diff --git a/screens/Proxiwash/ProxiwashScreen.js b/screens/Proxiwash/ProxiwashScreen.js index 11c13b4..0c7db1b 100644 --- a/screens/Proxiwash/ProxiwashScreen.js +++ b/screens/Proxiwash/ProxiwashScreen.js @@ -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 ( + onPress={this.onAboutPress}>