summaryrefslogtreecommitdiff
path: root/frontend/app/screens/menu/categoryMenu.js
blob: 6ed640041c2f92d82efa050e3a857dd8db32edfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react';
import PropTypes from 'prop-types';
import {
  TouchableHighlight,
  View,
  FlatList,
  StyleSheet,
} from 'react-native';
import {
  RkStyleSheet,
  RkTheme,
  RkText,
} from 'react-native-ui-kitten';
import NavigationType from '../../config/navigation/propTypes';

export class CategoryMenu extends React.Component {
  static propTypes = {
    navigation: NavigationType.isRequired,
    items: PropTypes.arrayOf(PropTypes.shape({
      title: PropTypes.string.isRequired,
    })).isRequired,
  };

  onItemPressed = (item) => {
    const url = item.action || item.id;
    this.props.navigation.navigate(url);
  };

  extractItemKey = (item) => item.id;

  renderItem = ({ item }) => (
    <TouchableHighlight
      style={styles.item}
      underlayColor={RkTheme.current.colors.button.underlay}
      activeOpacity={1}
      onPress={() => this.onItemPressed(item)}>
      <View>
        <RkText>{item.title}</RkText>
      </View>
    </TouchableHighlight>
  );

  renderPlaceholder = () => (
    <View style={styles.emptyContainer}>
      <RkText rkType='light subtitle'>Coming Soon...</RkText>
    </View>
  );

  renderList = () => (
    <FlatList
      style={styles.list}
      data={this.props.items}
      keyExtractor={this.extractItemKey}
      renderItem={this.renderItem}
    />
  );

  render = () => (this.props.items.length === 0 ? this.renderPlaceholder() : this.renderList());
}

const styles = RkStyleSheet.create(theme => ({
  item: {
    paddingVertical: 32.5,
    paddingHorizontal: 16.5,
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderColor: theme.colors.border.base,
  },
  list: {
    backgroundColor: theme.colors.screen.base,
  },
  emptyContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: theme.colors.screen.base,
  },
}));