Advertisement
yosadade

kerjakansoal.js

Jul 14th, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.57 KB | None | 0 0
  1. /* eslint-disable no-alert */
  2. /* eslint-disable react-native/no-inline-styles */
  3. import React, {useState} from 'react';
  4. import {RFValue} from 'react-native-responsive-fontsize';
  5. import {useSelector} from 'react-redux';
  6. import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
  7. import {
  8. StyleSheet,
  9. Text,
  10. View,
  11. ScrollView,
  12. TouchableOpacity,
  13. } from 'react-native';
  14. import {fonts, colors} from '../../utils';
  15. import {Gap, Button, StatusBar, Timer, Column} from '../../components';
  16. import Card from '../../components/atom/Card';
  17.  
  18. const ContentSoal = ({navigation}) => {
  19. const stateGlobal = useSelector(state => state);
  20.  
  21. const [count, setCount] = useState(0);
  22. const [no, setNo] = useState(stateGlobal.exams[count].id);
  23. const [title, setTitle] = useState(stateGlobal.exams[count].title);
  24. const [content, setContent] = useState(stateGlobal.exams[count].content);
  25. const [pageNumber, setPageNumber] = useState(0);
  26.  
  27. const back = () => {
  28. if (count <= 0) {
  29. setNo(stateGlobal.exams[0].id);
  30. setCount(0);
  31. setContent(stateGlobal.exams[0].content);
  32. } else if (stateGlobal.exams.length >= count) {
  33. setNo(stateGlobal.exams[count].id);
  34. setCount(count - 1);
  35. setContent(stateGlobal.exams[count].content);
  36. console.log(count);
  37. }
  38. };
  39. const next = () => {
  40. if (count < stateGlobal.exams.length - 1) {
  41. setCount(count + 1);
  42. setNo(stateGlobal.exams[count].id);
  43. setTitle(stateGlobal.exams[count].title);
  44. setContent(stateGlobal.exams[count].content);
  45. } else if (count === stateGlobal.exams.length - 1) {
  46. // eslint-disable-next-line no-alert
  47. alert('Kerjakan Soal Selesai');
  48. navigation.replace('ConfirmExam');
  49. }
  50. };
  51. return (
  52. <ScrollView showsVerticalScrollIndicator={false}>
  53. <RenderStatusBar />
  54. <View style={styles.page}>
  55. <View style={styles.container}>
  56. <ScrollView showsVerticalScrollIndicator={false}>
  57. <RenderHeader no={no} />
  58. <RenderContent
  59. title={title}
  60. content={content}
  61. no={no}
  62. // kunci={kunci}
  63. />
  64. <RenderButton back={back} next={next} />
  65. </ScrollView>
  66. </View>
  67. <RenderPagination />
  68. </View>
  69. </ScrollView>
  70. );
  71. };
  72.  
  73. const RenderStatusBar = () => {
  74. return (
  75. <StatusBar type="secondary" background={colors.background.quarterly} />
  76. );
  77. };
  78.  
  79. const RenderHeader = ({no}) => {
  80. return (
  81. <View style={styles.header}>
  82. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  83. <Text style={styles.titleSoal}>SOAL NO</Text>
  84. <View style={styles.wrapperNumber}>
  85. <Text style={styles.title}>{no}</Text>
  86. </View>
  87. </View>
  88. <Timer />
  89. </View>
  90. );
  91. };
  92.  
  93. const RenderContent = ({title, content, no}) => {
  94. return (
  95. <View>
  96. <View>
  97. <Card title={title} desc={content[0]} />
  98. <View style={styles.choice}>
  99. <Card type="pilihanGanda" desc={content[1]} />
  100. <Gap width={20} />
  101. <Card type="pilihanGanda" desc={content[2]} />
  102. </View>
  103.  
  104. <View style={styles.choice}>
  105. <Card type="pilihanGanda" desc={content[3]} />
  106. <Gap width={20} />
  107. <Card type="pilihanGanda" desc={content[4]} />
  108. </View>
  109. </View>
  110. <RenderFooter no={no} />
  111. </View>
  112. );
  113. };
  114.  
  115. const RenderFooter = ({no}) => {
  116. return (
  117. <View style={{marginTop: 20}}>
  118. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  119. <Column title="Status" />
  120. <Column type="secondary" title="Belum dijawab" />
  121. </View>
  122. <View
  123. style={{
  124. flexDirection: 'row',
  125. marginTop: 20,
  126. alignItems: 'center',
  127. justifyContent: 'space-between',
  128. width: 190,
  129. }}>
  130. <Text style={styles.title}>DIKERJAKAN</Text>
  131. <Column type="tertiary" title={`0${no}`} />
  132. </View>
  133. <View
  134. style={{
  135. flexDirection: 'row',
  136. marginTop: 5,
  137. alignItems: 'center',
  138. justifyContent: 'space-between',
  139. width: 190,
  140. }}>
  141. <Text style={styles.title}>BELUM DIKERJAKAN</Text>
  142. <Column type="tertiary" title="00" />
  143. </View>
  144. </View>
  145. );
  146. };
  147.  
  148. const RenderPagination = () => {
  149. const stateGlobal = useSelector(state => state);
  150. return (
  151. <View style={styles.pagination}>
  152. <View style={styles.containerPagination}>
  153. <Text style={styles.title}>Soal</Text>
  154. {stateGlobal.exams.map(item => {
  155. return (
  156. <TouchableOpacity style={styles.wrapperSoalActive} key={item.id}>
  157. <Text style={styles.title} key={item.id}>
  158. {item.id}
  159. </Text>
  160. </TouchableOpacity>
  161. );
  162. })}
  163. <TouchableOpacity style={styles.wrapperIcon}>
  164. <MaterialCommunityIcons
  165. name="chevron-down-circle-outline"
  166. size={26}
  167. color={colors.background.secondary}
  168. />
  169. </TouchableOpacity>
  170. </View>
  171. </View>
  172. );
  173. };
  174.  
  175. const RenderButton = ({count, back, next}) => {
  176. return (
  177. <View style={styles.button}>
  178. <Text>{count}</Text>
  179. <Button type="miniButtonInactive" title="BACK" onPress={back} />
  180. <Gap width={20} />
  181. <Button type="miniButtonActive" title="NEXT" onPress={next} />
  182. </View>
  183. );
  184. };
  185.  
  186. export default ContentSoal;
  187.  
  188. const styles = StyleSheet.create({
  189. page: {
  190. backgroundColor: '#FF9233',
  191. flex: 1,
  192. flexDirection: 'row',
  193. justifyContent: 'space-between',
  194. },
  195. container: {
  196. paddingVertical: 20,
  197. paddingHorizontal: 20,
  198. backgroundColor: '#FF9233',
  199. justifyContent: 'flex-start',
  200. width: '90%',
  201. },
  202. titleSoal: {
  203. fontSize: RFValue(15, 580),
  204. fontFamily: fonts.primary[800],
  205. color: colors.text.secondary,
  206. textAlign: 'center',
  207. },
  208. title: {
  209. fontSize: RFValue(12, 580),
  210. fontFamily: fonts.primary[800],
  211. color: colors.text.secondary,
  212. textAlign: 'center',
  213. },
  214. header: {
  215. flexDirection: 'row',
  216. alignItems: 'flex-start',
  217. // justifyContent: 'space-between',
  218. },
  219. choice: {
  220. flexDirection: 'row',
  221. justifyContent: 'space-between',
  222. },
  223. wrapperNumber: {
  224. backgroundColor: colors.background.secondary,
  225. marginLeft: 10,
  226. paddingHorizontal: 10,
  227. paddingVertical: 5,
  228. alignItems: 'center',
  229. justifyContent: 'center',
  230. borderRadius: 5,
  231. },
  232. pagination: {
  233. paddingVertical: 20,
  234. },
  235. containerPagination: {
  236. backgroundColor: colors.background.tertiary,
  237. padding: 7,
  238. alignItems: 'center',
  239. borderRadius: 5,
  240. marginLeft: 'auto',
  241. },
  242. wrapperSoalActive: {
  243. backgroundColor: colors.background.secondary,
  244. height: 25,
  245. width: 25,
  246. alignItems: 'center',
  247. justifyContent: 'center',
  248. marginTop: 10,
  249. borderRadius: 5,
  250. },
  251. wrapperSoalInactive: {
  252. backgroundColor: colors.background.primary,
  253. height: 25,
  254. width: 25,
  255. alignItems: 'center',
  256. justifyContent: 'center',
  257. marginTop: 10,
  258. borderRadius: 5,
  259. },
  260. titleInactive: {
  261. fontSize: 12,
  262. fontFamily: fonts.primary[800],
  263. color: colors.text.primary,
  264. textAlign: 'center',
  265. },
  266. wrapperIcon: {
  267. backgroundColor: 'transparent',
  268. height: 25,
  269. width: 25,
  270. alignItems: 'center',
  271. justifyContent: 'center',
  272. marginTop: 10,
  273. borderRadius: 5,
  274. },
  275. button: {
  276. paddingTop: 20,
  277. flexDirection: 'row',
  278. },
  279. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement