Commit 1efb465a authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Improve pizza error messages

parent 70e600d8
...@@ -6,19 +6,13 @@ import Icon from 'react-native-vector-icons/MaterialIcons'; ...@@ -6,19 +6,13 @@ import Icon from 'react-native-vector-icons/MaterialIcons';
import Moment from 'moment'; import Moment from 'moment';
import 'moment/locale/nl'; import 'moment/locale/nl';
import LoadingScreen from './LoadingScreen'; import LoadingScreen from './LoadingScreen';
import ErrorScreen from './ErrorScreen';
import { retrievePizzaInfo, cancelOrder, orderPizza } from '../actions/pizza'; import { retrievePizzaInfo, cancelOrder, orderPizza } from '../actions/pizza';
import styles from './style/pizza'; import styles from './style/pizza';
import { colors } from '../style'; import { colors } from '../style';
class Pizza extends Component { class Pizza extends Component {
constructor(props) {
super(props);
this.state = {
refreshing: false,
};
}
getProductFromList = (pk, pizzaList) => { getProductFromList = (pk, pizzaList) => {
for (let i = 0; i < pizzaList.length; i += 1) { for (let i = 0; i < pizzaList.length; i += 1) {
if (pizzaList[i].pk === pk) { if (pizzaList[i].pk === pk) {
...@@ -122,9 +116,7 @@ class Pizza extends Component { ...@@ -122,9 +116,7 @@ class Pizza extends Component {
); );
handleRefresh = () => { handleRefresh = () => {
this.setState({ refreshing: true });
this.props.retrievePizzaInfo(this.props.token); this.props.retrievePizzaInfo(this.props.token);
this.setState({ refreshing: false });
}; };
render() { render() {
...@@ -135,16 +127,13 @@ class Pizza extends Component { ...@@ -135,16 +127,13 @@ class Pizza extends Component {
<ScrollView <ScrollView
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
refreshing={this.state.refreshing} refreshing={this.props.loading}
onRefresh={this.handleRefresh} onRefresh={this.handleRefresh}
/> />
} }
contentContainerStyle={styles.content}
> >
<View style={styles.content}> <ErrorScreen message="Sorry! We couldn't load any data." />
<Text
style={styles.title}
>Something went wrong while retrieving pizza info.</Text>
</View>
</ScrollView> </ScrollView>
); );
} else if (!this.props.event) { } else if (!this.props.event) {
...@@ -152,16 +141,15 @@ class Pizza extends Component { ...@@ -152,16 +141,15 @@ class Pizza extends Component {
<ScrollView <ScrollView
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
refreshing={this.state.refreshing} refreshing={this.props.loading}
onRefresh={this.handleRefresh} onRefresh={this.handleRefresh}
/> />
} }
contentContainerStyle={styles.content}
> >
<View style={styles.content}> <Text
<Text style={styles.title}
style={styles.title} >There is currently no event for which you can order food.</Text>
>There is currently no event for which you can order food.</Text>
</View>
</ScrollView> </ScrollView>
); );
} }
...@@ -186,7 +174,7 @@ class Pizza extends Component { ...@@ -186,7 +174,7 @@ class Pizza extends Component {
<ScrollView <ScrollView
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
refreshing={this.state.refreshing} refreshing={this.props.loading}
onRefresh={this.handleRefresh} onRefresh={this.handleRefresh}
/> />
} }
...@@ -205,6 +193,7 @@ class Pizza extends Component { ...@@ -205,6 +193,7 @@ class Pizza extends Component {
Pizza.propTypes = { Pizza.propTypes = {
success: PropTypes.bool.isRequired, success: PropTypes.bool.isRequired,
loading: PropTypes.bool.isRequired,
hasLoaded: PropTypes.bool.isRequired, hasLoaded: PropTypes.bool.isRequired,
event: PropTypes.shape({ event: PropTypes.shape({
start: PropTypes.string.isRequired, start: PropTypes.string.isRequired,
...@@ -239,7 +228,8 @@ Pizza.defaultProps = { ...@@ -239,7 +228,8 @@ Pizza.defaultProps = {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
success: state.pizza.success, success: state.pizza.success,
hasLoaded: state.pizza.success, loading: state.pizza.loading,
hasLoaded: state.pizza.hasLoaded,
event: state.pizza.event, event: state.pizza.event,
order: state.pizza.order, order: state.pizza.order,
pizzaList: state.pizza.pizzaList, pizzaList: state.pizza.pizzaList,
......
...@@ -2,6 +2,7 @@ import * as pizzaActions from '../actions/pizza'; ...@@ -2,6 +2,7 @@ import * as pizzaActions from '../actions/pizza';
const initialState = { const initialState = {
success: false, success: false,
loading: false,
hasLoaded: false, hasLoaded: false,
event: null, event: null,
order: null, order: null,
...@@ -13,6 +14,7 @@ export default function pizza(state = initialState, action = {}) { ...@@ -13,6 +14,7 @@ export default function pizza(state = initialState, action = {}) {
case pizzaActions.SUCCESS: case pizzaActions.SUCCESS:
return { return {
success: true, success: true,
loading: false,
hasLoaded: true, hasLoaded: true,
event: action.payload.event, event: action.payload.event,
order: action.payload.order, order: action.payload.order,
...@@ -22,12 +24,13 @@ export default function pizza(state = initialState, action = {}) { ...@@ -22,12 +24,13 @@ export default function pizza(state = initialState, action = {}) {
return { return {
...state, ...state,
success: false, success: false,
loading: false,
hasLoaded: true, hasLoaded: true,
}; };
case pizzaActions.FETCHING: case pizzaActions.FETCHING:
return { return {
...state, ...state,
hasLoaded: false, loading: true,
}; };
case pizzaActions.CANCEL_SUCCESS: case pizzaActions.CANCEL_SUCCESS:
return { return {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment