-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModalView.js
155 lines (136 loc) · 4.12 KB
/
ModalView.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import React, {useState, useEffect} from 'react';
import {Dimensions, View} from 'react-native';
import {connect} from 'react-redux';
import * as actions from '../redux/actions';
import {CustomPicker} from 'react-native-custom-picker';
import Modal from 'react-native-modal';
import Text from './base/Text';
import ActionButton, {ActionButtonTitle} from './ActionButton';
import Column from './base/Column';
import Row from './base/Row';
const ModalView = ({
visible,
loading,
setVisible,
categories,
questions,
startGame,
selectedCategoryId,
navigation,
}) => {
const [difficulty, setDifficulty] = useState('easy');
const [category, setCategory] = useState([]);
// Only categories labels
const editedCategory = categories.map((c) => c.label);
// Get selected category id
const getCategoryId = (selectedCategory) =>
categories.find((c) => c.label === selectedCategory);
const selectedCategoryIdState = getCategoryId(category);
// Custom Picker Settings
const renderHeader = () => {
return (
<Row justifyContent="flex-start" m={10}>
<Text fontSize={18} fontFamily="Poppins-Medium" color="purple">
All Categories
</Text>
</Row>
);
};
const renderField = (settings) => {
const {selectedItem, defaultText, getLabel} = settings;
return (
<View>
<View>
{!selectedItem && (
<View>
<Text color="blue">{defaultText}</Text>
</View>
)}
{selectedItem && (
<View>
<Text color="blue">{getLabel(selectedItem)}</Text>
</View>
)}
</View>
</View>
);
};
const renderOption = (settings) => {
const {item, getLabel} = settings;
return (
<Row justifyContent="flex-start" m={10} borderRadius={8}>
<Text fontSize={16} color="black">
{getLabel(item)}
</Text>
</Row>
);
};
return (
<Column bg="red">
<Modal isVisible={visible}>
<Column bg="white" p={20} borderRadius={8}>
<Text fontFamily="Poppins-Bold" fontSize={24} color="black">
LET'S CREATE A QUIZ!
</Text>
<Row
justifyContent="space-evenly"
width={Dimensions.get('window').width / 2}
m={10}>
<Text fontFamily="Poppins-Medium" color="black" mr={80}>
Difficulty
</Text>
<CustomPicker
placeholder="Select Difficulty"
options={['Easy', 'Medium', 'Hard']}
fieldTemplate={renderField}
optionTemplate={renderOption}
headerTemplate={renderHeader}
onValueChange={(value) => {
setDifficulty(value.toLowerCase());
}}
/>
</Row>
<Row
justifyContent="space-evenly"
width={Dimensions.get('window').width / 2}>
<Text fontFamily="Poppins-Medium" color="black" mr={80}>
Category
</Text>
{loading === true ? (
<Text> Loading... </Text>
) : (
<CustomPicker
placeholder="Select Category"
options={editedCategory}
fieldTemplate={renderField}
optionTemplate={renderOption}
headerTemplate={renderHeader}
onValueChange={(value) => {
setCategory(value);
}}
/>
)}
</Row>
<ActionButton
borderRadius={30}
mt={20}
onPress={() => {
startGame(difficulty, selectedCategoryIdState);
setVisible(!visible);
setTimeout(() => navigation.navigate('Questions'), 500);
}}
bg="purple">
<ActionButtonTitle color="white">START QUIZ</ActionButtonTitle>
</ActionButton>
</Column>
</Modal>
</Column>
);
};
const mapStateToProps = ({questionsReducer}) => {
const {loading} = questionsReducer;
return {
loading,
};
};
export default connect(mapStateToProps, actions)(ModalView);