Advertisement
yosadade

soal.js

Jul 13th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 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 {useSelector} from 'react-redux';
  5. import {StyleSheet, Text, View, ScrollView} from 'react-native';
  6. import {fonts, colors} from '../../utils';
  7. import {
  8. Gap,
  9. Button,
  10. StatusBar,
  11. PaginationSoal,
  12. Timer,
  13. Column,
  14. } from '../../components';
  15. import Card from '../../components/atom/Card';
  16.  
  17. const ContentSoal = ({navigation}) => {
  18. const stateGlobal = useSelector(state => state);
  19.  
  20. const [count, setCount] = useState(0);
  21. const [no, setNo] = useState(stateGlobal.exams[count].id);
  22. const [title, setTitle] = useState(stateGlobal.exams[count].title);
  23. const [content, setContent] = useState(stateGlobal.exams[count].content);
  24.  
  25. const back = () => {
  26. if (stateGlobal.exams.length >= count) {
  27. setNo(stateGlobal.exams[count].id);
  28. setCount(count - 1);
  29. setContent(stateGlobal.exams[count].content);
  30. console.log(count);
  31. } else if (count <= 0) {
  32. alert('asdadad');
  33. setNo(stateGlobal.exams[0].id);
  34. setCount(0);
  35. setContent(stateGlobal.exams[0].content);
  36. }
  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. // kunci={kunci}
  62. />
  63. <RenderButton back={back} next={next} />
  64. </ScrollView>
  65. </View>
  66. <RenderPagination />
  67. </View>
  68. </ScrollView>
  69. );
  70. };
  71.  
  72. const RenderStatusBar = () => {
  73. return (
  74. <StatusBar type="secondary" background={colors.background.quarterly} />
  75. );
  76. };
  77.  
  78. const RenderHeader = ({no}) => {
  79. return (
  80. <View style={styles.header}>
  81. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  82. <Text style={styles.titleSoal}>SOAL NO</Text>
  83. <View style={styles.wrapperNumber}>
  84. <Text style={styles.title}>{no}</Text>
  85. </View>
  86. </View>
  87. <Timer />
  88. </View>
  89. );
  90. };
  91.  
  92. const RenderContent = ({title, content, kunci}) => {
  93. // const type = () => {
  94. // if (kunci) {
  95. // return 'pilihanBenar';
  96. // } else {
  97. // return 'pilihanGanda';
  98. // }
  99. // };
  100. return (
  101. <View>
  102. <View>
  103. <Card title={title} desc={content[0]} />
  104. <View style={styles.choice}>
  105. <Card type="pilihanGanda" desc={content[1]} />
  106. <Gap width={20} />
  107. <Card type="pilihanGanda" desc={content[2]} />
  108. </View>
  109.  
  110. <View style={styles.choice}>
  111. <Card type="pilihanGanda" desc={content[3]} />
  112. <Gap width={20} />
  113. <Card type="pilihanGanda" desc={content[4]} />
  114. </View>
  115. </View>
  116. <RenderFooter />
  117. </View>
  118. );
  119. };
  120.  
  121. const RenderFooter = () => {
  122. return (
  123. <View style={{marginTop: 20}}>
  124. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  125. <Column title="Status" />
  126. <Column type="secondary" title="Belum dijawab" />
  127. </View>
  128. <View
  129. style={{
  130. flexDirection: 'row',
  131. marginTop: 20,
  132. alignItems: 'center',
  133. justifyContent: 'space-between',
  134. width: 190,
  135. }}>
  136. <Text style={styles.title}>DIKERJAKAN</Text>
  137. <Column type="tertiary" title="00" />
  138. </View>
  139. <View
  140. style={{
  141. flexDirection: 'row',
  142. marginTop: 5,
  143. alignItems: 'center',
  144. justifyContent: 'space-between',
  145. width: 190,
  146. }}>
  147. <Text style={styles.title}>BELUM DIKERJAKAN</Text>
  148. <Column type="tertiary" title="00" />
  149. </View>
  150. </View>
  151. );
  152. };
  153.  
  154. const RenderPagination = () => {
  155. return (
  156. <View style={styles.pagination}>
  157. <PaginationSoal />
  158. </View>
  159. );
  160. };
  161.  
  162. const RenderButton = ({count, back, next}) => {
  163. // const onNext = () => {
  164. // alert(count)
  165. // };
  166. return (
  167. <View style={styles.button}>
  168. <Text>{count}</Text>
  169. <Button type="miniButtonInactive" title="BACK" onPress={back} />
  170. <Gap width={20} />
  171. <Button type="miniButtonActive" title="NEXT" onPress={next} />
  172. </View>
  173. );
  174. };
  175.  
  176. export default ContentSoal;
  177.  
  178. const styles = StyleSheet.create({
  179. page: {
  180. backgroundColor: '#FF9233',
  181. flex: 1,
  182. flexDirection: 'row',
  183. justifyContent: 'space-between',
  184. },
  185. container: {
  186. paddingVertical: 20,
  187. paddingHorizontal: 20,
  188. backgroundColor: '#FF9233',
  189. justifyContent: 'flex-start',
  190. },
  191. titleSoal: {
  192. fontSize: 15,
  193. fontFamily: fonts.primary[800],
  194. color: colors.text.secondary,
  195. textAlign: 'center',
  196. },
  197. title: {
  198. fontSize: 12,
  199. fontFamily: fonts.primary[800],
  200. color: colors.text.secondary,
  201. textAlign: 'center',
  202. },
  203. header: {
  204. flexDirection: 'row',
  205. alignItems: 'flex-start',
  206. // justifyContent: 'space-between',
  207. },
  208. choice: {
  209. flexDirection: 'row',
  210. justifyContent: 'center',
  211. },
  212. wrapperNumber: {
  213. backgroundColor: colors.background.secondary,
  214. marginLeft: 10,
  215. paddingHorizontal: 10,
  216. paddingVertical: 5,
  217. alignItems: 'center',
  218. justifyContent: 'center',
  219. borderRadius: 5,
  220. },
  221. pagination: {
  222. paddingVertical: 20,
  223. },
  224. button: {
  225. paddingTop: 20,
  226. flexDirection: 'row',
  227. },
  228. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement