-
Notifications
You must be signed in to change notification settings - Fork 0
/
submission_ChongLipPhang.patch
4226 lines (4224 loc) · 276 KB
/
submission_ChongLipPhang.patch
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/App.tsx b/App.tsx
index f8b946d..fe5bbf1 100644
--- a/App.tsx
+++ b/App.tsx
@@ -1,20 +1,51 @@
-import { StatusBar } from 'expo-status-bar';
-import { StyleSheet, Text, View } from 'react-native';
+export const time = 30;
+export const q_total = 5;
+export const correct = 20;
+export const wrong = -20;
+export const skip = -10;
-export default function App() {
- return (
- <View style={styles.container}>
- <Text>Open up App.tsx to start working on your app!</Text>
- <StatusBar style="auto" />
- </View>
- );
-}
+import { NavigationContainer } from "@react-navigation/native";
+import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faHouse, faCompass, faStopwatch, faBookmark, faCircleUser } from '@fortawesome/free-solid-svg-icons';
+import Activity from "./components/Activity";
+import Bookmarks from "./components/Bookmarks";
+import Discover from "./components/Discover";
+import Home from "./components/Home";
+import Profile from "./components/Profile";
+
+const Tab = createBottomTabNavigator();
-const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#fff',
- alignItems: 'center',
- justifyContent: 'center',
- },
-});
+export default function App() {
+ return (
+ <NavigationContainer>
+ <Tab.Navigator
+ screenOptions={({ route }) => ({
+ headerShown: false,
+ tabBarStyle: { borderTopWidth: 0 },
+ tabBarActiveBackgroundColor: "black",
+ tabBarInactiveBackgroundColor: "black",
+ tabBarActiveTintColor:"white",
+ tabBarInactiveTintColor:"grey",
+ tabBarIcon: ({ focused, color, size }) => {
+ let ico:any = {
+ "Home" : faHouse,
+ "Discover" : faCompass,
+ "Activity" : faStopwatch,
+ "Bookmarks": faBookmark,
+ "Profile" : faCircleUser
+ }[route.name];
+ //console.log(route);
+ return <FontAwesomeIcon icon={ico} color={focused?"white":"grey"}/>
+ }
+ })}
+ >
+ <Tab.Screen name="Home" component={Home} />
+ <Tab.Screen name="Discover" component={Discover} />
+ <Tab.Screen name="Activity" component={Activity} />
+ <Tab.Screen name="Bookmarks" component={Bookmarks} />
+ <Tab.Screen name="Profile" component={Profile} />
+ </Tab.Navigator>
+ </NavigationContainer>
+ );
+}
\ No newline at end of file
diff --git a/TT.zip b/TT.zip
new file mode 100644
index 0000000..8271db6
Binary files /dev/null and b/TT.zip differ
diff --git a/components/Activity/Daily/index.tsx b/components/Activity/Daily/index.tsx
new file mode 100644
index 0000000..ddb6553
--- /dev/null
+++ b/components/Activity/Daily/index.tsx
@@ -0,0 +1,9 @@
+import { View, Text } from "react-native";
+
+export const Daily = function(){
+ return (
+ <View style={{flex:1, backgroundColor:"black", paddingVertical:"30%"}}>
+ <Text style={{fontSize:30, color:"white"}}>Daily</Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Activity/Monthly/index.tsx b/components/Activity/Monthly/index.tsx
new file mode 100644
index 0000000..600dcd6
--- /dev/null
+++ b/components/Activity/Monthly/index.tsx
@@ -0,0 +1,9 @@
+import { View, Text } from "react-native";
+
+export const Monthly = function(){
+ return (
+ <View style={{flex:1, backgroundColor:"black", paddingVertical:"30%"}}>
+ <Text style={{fontSize:30, color:"white"}}>Monthly</Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Activity/Weekly/index.tsx b/components/Activity/Weekly/index.tsx
new file mode 100644
index 0000000..f6095ca
--- /dev/null
+++ b/components/Activity/Weekly/index.tsx
@@ -0,0 +1,9 @@
+import { View, Text } from "react-native";
+
+export const Weekly = function(){
+ return (
+ <View style={{flex:1, backgroundColor:"black", paddingVertical:"30%"}}>
+ <Text style={{fontSize:30, color:"white"}}>Weekly</Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Activity/index.tsx b/components/Activity/index.tsx
new file mode 100644
index 0000000..b5cc20e
--- /dev/null
+++ b/components/Activity/index.tsx
@@ -0,0 +1,12 @@
+import { Daily } from './Daily';
+import { Weekly } from './Weekly';
+import { Monthly } from './Monthly';
+import HorizontalNavigator from "../shared/HorizontalNavigator";
+
+export default function Home(){
+ return (
+ <HorizontalNavigator screens = {[["Daily",Daily],
+ ["Weekly",Weekly],
+ ["Monthly",Monthly]]} />
+ );
+}
\ No newline at end of file
diff --git a/components/Bookmarks/index.tsx b/components/Bookmarks/index.tsx
new file mode 100644
index 0000000..8434cfe
--- /dev/null
+++ b/components/Bookmarks/index.tsx
@@ -0,0 +1,9 @@
+import { View, Text } from "react-native";
+
+export default function Bookmarks(){
+ return (
+ <View style={{flex:1, backgroundColor:"black", paddingVertical:"30%"}}>
+ <Text style={{fontSize:50, color:"white"}}>Bookmarks</Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Discover/index.tsx b/components/Discover/index.tsx
new file mode 100644
index 0000000..4b6522c
--- /dev/null
+++ b/components/Discover/index.tsx
@@ -0,0 +1,9 @@
+import { View, Text } from "react-native";
+
+export default function Discover(){
+ return (
+ <View style={{flex:1, backgroundColor:"black", paddingVertical:"30%"}}>
+ <Text style={{fontSize:50, color:"white"}}>Discover</Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/BookmarkButton.tsx b/components/Home/ForYou/BookmarkButton.tsx
new file mode 100644
index 0000000..5b526e9
--- /dev/null
+++ b/components/Home/ForYou/BookmarkButton.tsx
@@ -0,0 +1,13 @@
+
+import { View, Text } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faBookmark } from '@fortawesome/free-solid-svg-icons';
+
+export function BookmarkButton(){
+ return (
+ <View style={{flex:1}}>
+ <FontAwesomeIcon icon={faBookmark} color="white"/>
+ <Text style={{color:"white", width:"100%", textAlign:"center"}}>9 </Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/CommentButton.tsx b/components/Home/ForYou/CommentButton.tsx
new file mode 100644
index 0000000..60bb3f6
--- /dev/null
+++ b/components/Home/ForYou/CommentButton.tsx
@@ -0,0 +1,13 @@
+
+import { View, Text } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faCommentDots } from '@fortawesome/free-solid-svg-icons';
+
+export function CommentButton(){
+ return (
+ <View style={{flex:1}}>
+ <FontAwesomeIcon icon={faCommentDots} color="white"/>
+ <Text style={{color:"white", width:"100%", textAlign:"center"}}>78 </Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/DescriptionBar.tsx b/components/Home/ForYou/DescriptionBar.tsx
new file mode 100644
index 0000000..1e1c253
--- /dev/null
+++ b/components/Home/ForYou/DescriptionBar.tsx
@@ -0,0 +1,43 @@
+
+import { memo } from "react";
+import { View, Text, Dimensions, StyleSheet } from "react-native";
+import { QuestionType } from "./qaFetching";
+
+const sh = Dimensions.get('window').height
+
+export const DescriptionBar = memo(function({question, flex}:{question:QuestionType, flex:number}){
+ //console.log("rendering DescriptionBar");
+ return (
+ <View style={{ flex: flex}}>
+ <Text style={styles.name}>
+ {question.user.name}
+ </Text>
+ <Text style={styles.description}>
+ {question.description}
+ <Text style={{...styles.description, fontWeight:"bold"}}>
+ #{question.tag}
+ </Text>
+ </Text>
+ </View>
+ );
+});
+
+const styles = StyleSheet.create({
+ name:{
+ color:"white",
+ marginBottom: 0,
+ margin:0,
+ paddingTop:sh*0.005,
+ paddingLeft:"3%",
+ fontSize: sh*0.02,
+ fontWeight: "bold"
+ },
+ description:{
+ color:"white",
+ marginBottom: 0,
+ margin:0,
+ paddingTop:sh*0.005,
+ paddingLeft:"3%",
+ fontSize: sh*0.015,
+ },
+})
\ No newline at end of file
diff --git a/components/Home/ForYou/FavoriteButton.tsx b/components/Home/ForYou/FavoriteButton.tsx
new file mode 100644
index 0000000..f713734
--- /dev/null
+++ b/components/Home/ForYou/FavoriteButton.tsx
@@ -0,0 +1,13 @@
+
+import { View, Text } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faHeart } from '@fortawesome/free-solid-svg-icons';
+
+export function FavoriteButton(){
+ return (
+ <View style={{flex:1}}>
+ <FontAwesomeIcon icon={faHeart} color="white"/>
+ <Text style={{color:"white", width:"100%", textAlign:"center"}}>194 </Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/MiddlePanel.tsx b/components/Home/ForYou/MiddlePanel.tsx
new file mode 100644
index 0000000..a2e174c
--- /dev/null
+++ b/components/Home/ForYou/MiddlePanel.tsx
@@ -0,0 +1,21 @@
+
+import { memo } from "react";
+import { View } from "react-native";
+import { OptionsList } from "./OptionsList";
+import { DescriptionBar } from "./DescriptionBar";
+import { QuestionType } from "./qaFetching";
+
+export const MiddlePanel = memo (function({question,setScore,countScore,setQAnswered,flex}:{question:QuestionType,setScore:Function,countScore:boolean,setQAnswered:Function, flex:number}){
+ //console.log("rendering MiddlePanel");
+ return (
+ <View style={{ flex: flex, flexDirection: "row"}}>
+ <View style={{ flex:18, flexDirection:"row"}}>
+ <View style={{ flex: 1}}>
+ <OptionsList question={question} setScore={setScore} countScore={countScore} setQAnswered={ setQAnswered } flex={6}/>
+ <DescriptionBar question={question} flex={1}/>
+ </View>
+ </View>
+ <View style={{flex:2}}></View>
+ </View>
+ );
+});
\ No newline at end of file
diff --git a/components/Home/ForYou/NewButton.tsx b/components/Home/ForYou/NewButton.tsx
new file mode 100644
index 0000000..5731305
--- /dev/null
+++ b/components/Home/ForYou/NewButton.tsx
@@ -0,0 +1,22 @@
+
+import { View, Text, TouchableHighlight } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faScroll } from '@fortawesome/free-solid-svg-icons';
+
+export function NewButton({started, setStarted}:{started:boolean, setStarted:Function}){
+ //console.log("rendering NewButton");
+ return (
+ <TouchableHighlight style={{flex:1}} underlayColor="transparent" onPress={()=> {
+ setStarted((s:boolean)=>!s);
+ }}>
+ <View>
+ <View style={{backgroundColor:"#947521", paddingTop:6, paddingLeft:8, borderRadius:20, width:35, height:35, borderColor:"white", borderWidth:1, marginLeft:-5}}>
+ <FontAwesomeIcon icon={faScroll} color="orange" transform="grow-2"/>
+ </View>
+ <View style={{backgroundColor:started?"red":"green", padding:1, borderRadius:8, width:15, height:15, borderColor:"white", marginTop:-8, marginLeft:5}}>
+ <Text style={{color:"white", width:"100%", textAlign:"center", fontSize:14, fontWeight:"bold", marginTop:-4}}>{started?"E":"+"}</Text>
+ </View>
+ </View>
+ </TouchableHighlight>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/OptionsList.tsx b/components/Home/ForYou/OptionsList.tsx
new file mode 100644
index 0000000..4e27358
--- /dev/null
+++ b/components/Home/ForYou/OptionsList.tsx
@@ -0,0 +1,67 @@
+import { useState } from "react";
+import { View, Text, Dimensions, StyleSheet, TouchableHighlight } from "react-native";
+import { Image } from "expo-image";
+import { QuestionType } from "./qaFetching";
+import { OutlineText } from "../../shared/OutlineText";
+import { correct, wrong, skip } from "../../../App";
+
+const sh = Dimensions.get('window').height;
+
+export function OptionsList({question, setScore, countScore, setQAnswered, flex}:{question:QuestionType, setScore:Function, countScore:boolean, setQAnswered:Function, flex:number}){
+ const [playerAns, setPlayerAns] = useState("");
+ return ( // target background opacity divided by 8 due to 8 overlapping layers
+ <View style={{ flex: flex }}>
+ {question.options.map((o=>
+ <TouchableHighlight style={{ flex: 1, justifyContent: 'flex-start'}} key={o.id} underlayColor="transparent" onPress={()=>{
+ if (countScore) {
+ setScore((s:number)=>(s+((o.id==question.answer)?(correct-skip):(wrong-skip))));
+ setQAnswered((n:number)=>(n+1)); // count score if only part of the current test, ie. last 5 questions.
+ }
+ if (playerAns==="") {
+ setPlayerAns(o.id);
+ }
+ }}>
+ <View style={{flexDirection:"row"}}>
+ <View style={{flex:99}}>
+ <OutlineText stroke={ 2 }
+ color="black"
+ backgroundColor={((playerAns===question.answer && playerAns===o.id)?"rgba(40,177,143,0.0875)"
+ :(playerAns!==question.answer && playerAns===o.id)?"rgba(220,95,95,0.0875)"
+ :(playerAns!=="" && question.answer===o.id)?"rgba(40,177,143,0.0875)"
+ :"rgba(255,255,255,0.0625)")}>
+ <Text style={styles.option}>
+ {o.answer}
+ </Text>
+ </OutlineText>
+ </View>
+ <View style={{ flex:1,
+ position:"relative",
+ top:(playerAns===o.id && playerAns===question.answer)?sh*0.03:sh*0.06,
+ left:(playerAns===o.id && playerAns===question.answer)?"-70%":"20%",
+ transform:(playerAns===o.id && playerAns===question.answer)?"rotateZ(0deg)":"rotateZ(180deg)"}}>
+ { (playerAns===o.id)?((playerAns===question.answer)?
+ <Image source={require('../../../public/correct.gif')} contentFit="contain" style={styles.indicator}/>
+ :<Image source={require('../../../public/wrong.gif' )} contentFit="contain" style={styles.indicator}/>
+ ):null
+ }
+ </View>
+ </View>
+ </TouchableHighlight>
+ ))}
+ </View>
+ );
+}
+
+const styles = StyleSheet.create({
+ option: {
+ marginLeft:"5%",
+ padding:10,
+ paddingLeft: 0,
+ fontSize:sh*0.022,
+ color:"white",
+ },
+ indicator:{
+ width:sh*0.1,
+ height:sh*0.1,
+ }
+});
diff --git a/components/Home/ForYou/PlaylistBar.tsx b/components/Home/ForYou/PlaylistBar.tsx
new file mode 100644
index 0000000..0e3d4cd
--- /dev/null
+++ b/components/Home/ForYou/PlaylistBar.tsx
@@ -0,0 +1,36 @@
+import { memo } from "react";
+import { View, Text, Dimensions, StyleSheet } from "react-native";
+import { PlaylistSVG } from "./PlaylistSVG";
+import { QuestionType } from "./qaFetching";
+
+const sh = Dimensions.get('window').height
+
+export const PlaylistBar = memo(function({question, flex}:{question:QuestionType, flex:number}){
+ //console.log("rendering PlaylistBar");
+ return (
+ <View style={{ flex:flex, flexDirection:"row"}}>
+ <View style={{...styles.playlist, flex:14, flexDirection:"row" }}>
+ <PlaylistSVG />
+ <Text style={{color:"white", fontSize:sh*0.017, position:"relative", top:-sh*0.007}}>
+
+ Playlist • {question.unit} : {question.playlist}
+ </Text>
+ </View>
+ <Text style={{...styles.playlist, flex: 1, fontSize:sh*0.03, paddingTop:sh*0.003, color:"white"}}>
+ >
+ </Text>
+ </View>
+ );
+});
+
+const styles = StyleSheet.create({
+ playlist:{
+ backgroundColor: "#161616",
+ marginBottom: 0,
+ margin:0,
+ height: sh*0.1,
+ paddingTop:15,
+ paddingBottom:20,
+ paddingLeft:10,
+ }
+})
\ No newline at end of file
diff --git a/components/Home/ForYou/PlaylistSVG.tsx b/components/Home/ForYou/PlaylistSVG.tsx
new file mode 100644
index 0000000..3367893
--- /dev/null
+++ b/components/Home/ForYou/PlaylistSVG.tsx
@@ -0,0 +1,9 @@
+
+
+import Svg, { SvgProps, Path } from "react-native-svg";
+
+export const PlaylistSVG = (props: SvgProps) => ( // adapted from ./public/playlist.svg to avoid TypeScript warning
+ <Svg width="18" height="15" viewBox="0 2 18 5" fill="none">
+ <Path d="M6.19824 2.68164C4.17969 2.68164 2.92285 3.93213 2.92285 5.94434V11.1177H2.77686C1.37402 11.0859 0.618652 10.3052 0.618652 8.896V2.7832C0.618652 1.34229 1.41211 0.555176 2.85938 0.555176H11.4731C12.8696 0.555176 13.6504 1.28516 13.7075 2.63086V2.68164H6.19824ZM6.19824 14.2788C4.74463 14.2788 3.95752 13.4917 3.95752 12.0508V5.94434C3.95752 4.50342 4.74463 3.71631 6.19824 3.71631H14.8501C16.2974 3.71631 17.0908 4.50342 17.0908 5.94434V12.0508C17.0908 13.4917 16.2974 14.2788 14.8501 14.2788H6.19824ZM8.65479 11.2383C8.65479 11.543 8.99121 11.689 9.26416 11.5303L13.041 9.33398C13.3013 9.18164 13.2949 8.81982 13.0347 8.67383L9.26416 6.46484C8.99121 6.2998 8.65479 6.45215 8.65479 6.76953V11.2383Z" fill="white"/>
+ </Svg>
+);
diff --git a/components/Home/ForYou/QA_Panel.tsx b/components/Home/ForYou/QA_Panel.tsx
new file mode 100644
index 0000000..cc2586b
--- /dev/null
+++ b/components/Home/ForYou/QA_Panel.tsx
@@ -0,0 +1,22 @@
+import { memo } from "react";
+import { View, ImageSourcePropType, ImageBackground, Dimensions } from "react-native";
+import { QuestionType } from "./qaFetching";
+import { PlaylistBar } from "./PlaylistBar";
+import { QuestionPanel } from "./QuestionPanel";
+import { MiddlePanel } from "./MiddlePanel";
+
+const sh = Dimensions.get('window').height;
+
+export const QA_Panel = memo(function({question, setScore, countScore, setQAnswered}:{question:QuestionType, setScore:Function, countScore:boolean, setQAnswered:Function}){
+ //console.log("rendering QA_Panel");
+ return (
+ <View style={{ height:sh, backgroundColor: "black" }}>
+ <ImageBackground source={{uri:question.image} as ImageSourcePropType} resizeMode="cover" style={{flex:1}}>
+ <View style={{flex:7}}></View>
+ <QuestionPanel question={question} flex={19} />
+ <MiddlePanel question={question} setScore={setScore} countScore={ countScore } setQAnswered={ setQAnswered } flex={25} />
+ <PlaylistBar question={question} flex={4} />
+ </ImageBackground>
+ </View>
+ );
+});
diff --git a/components/Home/ForYou/QuestionPanel.tsx b/components/Home/ForYou/QuestionPanel.tsx
new file mode 100644
index 0000000..0ab35f5
--- /dev/null
+++ b/components/Home/ForYou/QuestionPanel.tsx
@@ -0,0 +1,38 @@
+
+import { memo } from "react";
+import { View, Text, Dimensions, StyleSheet } from "react-native";
+import { QuestionType } from "./qaFetching";
+
+const sh = Dimensions.get('window').height
+
+const NO_WIDTH_SPACE = '';
+const highlight = (s:string) =>
+ s.split(' ').map((word, i) => (
+ <Text key={i}>
+ <Text style={styles.highlight}>{word} </Text>
+ {NO_WIDTH_SPACE}
+ </Text>
+));
+
+export const QuestionPanel = memo(function({question, flex}:{question:QuestionType, flex:number}){
+ //console.log("rendering QuestionPanel");
+ return (
+ <View style={{ flex: flex}}>
+ <Text style={styles.question}>
+ {highlight(question.question)}
+ </Text>
+ </View>
+ );
+});
+
+const styles = StyleSheet.create({
+ question: {
+ padding: "8%",
+ fontSize:sh*0.03,
+ color:"white",
+ },
+
+ highlight:{
+ backgroundColor: "rgba(0,0,0,0.6)"
+ }
+})
\ No newline at end of file
diff --git a/components/Home/ForYou/SearchButton.tsx b/components/Home/ForYou/SearchButton.tsx
new file mode 100644
index 0000000..621a24c
--- /dev/null
+++ b/components/Home/ForYou/SearchButton.tsx
@@ -0,0 +1,17 @@
+
+import { View, Dimensions } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faSearch } from '@fortawesome/free-solid-svg-icons';
+
+const sh = Dimensions.get('window').height;
+const sw = Dimensions.get('window').width;
+
+export function SearchButton(){
+ return (
+ <View style={{flex:3}}>
+ <View style={{position:"absolute",bottom:sh*0.045, right:sw*0.04}}>
+ <FontAwesomeIcon icon={faSearch} color="white"/>
+ </View>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/ShareButton.tsx b/components/Home/ForYou/ShareButton.tsx
new file mode 100644
index 0000000..83a5d3a
--- /dev/null
+++ b/components/Home/ForYou/ShareButton.tsx
@@ -0,0 +1,13 @@
+
+import { View, Text } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faShare } from '@fortawesome/free-solid-svg-icons';
+
+export function ShareButton(){
+ return (
+ <View style={{flex:1}}>
+ <FontAwesomeIcon icon={faShare} color="white"/>
+ <Text style={{color:"white", width:"100%", textAlign:"center"}}>20 </Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/SideButtons.tsx b/components/Home/ForYou/SideButtons.tsx
new file mode 100644
index 0000000..f781797
--- /dev/null
+++ b/components/Home/ForYou/SideButtons.tsx
@@ -0,0 +1,20 @@
+import { memo } from "react";
+import { View } from "react-native";
+import { NewButton } from "./NewButton"
+import { FavoriteButton } from "./FavoriteButton";
+import { CommentButton } from "./CommentButton";
+import { BookmarkButton } from "./BookmarkButton";
+import { ShareButton } from "./ShareButton";
+
+export const SideButtons = memo(function({ started, setStarted }:{ started:boolean, setStarted:Function }){
+ //console.log("rendering SideButtons");
+ return (
+ <View style={{ position:"absolute", bottom:"5%", right:0, width:"10%", height:"45%"}}>
+ <NewButton started={started} setStarted={setStarted} />
+ <FavoriteButton/>
+ <CommentButton/>
+ <BookmarkButton/>
+ <ShareButton/>
+ </View>
+ );
+});
\ No newline at end of file
diff --git a/components/Home/ForYou/Timer.tsx b/components/Home/ForYou/Timer.tsx
new file mode 100644
index 0000000..32747ac
--- /dev/null
+++ b/components/Home/ForYou/Timer.tsx
@@ -0,0 +1,21 @@
+
+import { View, Text, Dimensions } from "react-native";
+import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
+import { faStopwatch } from '@fortawesome/free-solid-svg-icons';
+
+const sh = Dimensions.get('window').height
+const sw = Dimensions.get('window').width;
+
+export function Timer({seconds, setSeconds, started}:{seconds:number, setSeconds:Function, started:boolean}){
+ // console.log("rendering Timer");
+ return (
+ <View style={{flex:3}}>
+ <View style={{position:"absolute",bottom:sh*0.04, left:sw*0.03}}>
+ <Text style={{color:"white", fontSize:sh*0.022}}>
+ <FontAwesomeIcon icon={faStopwatch} color="white" transform="shrink-1 down-1"/>
+ {`${Math.floor(seconds/60)}m ${seconds % 60}s`}
+ </Text>
+ </View>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/Home/ForYou/TopBar.tsx b/components/Home/ForYou/TopBar.tsx
new file mode 100644
index 0000000..89a5b6a
--- /dev/null
+++ b/components/Home/ForYou/TopBar.tsx
@@ -0,0 +1,17 @@
+import { memo } from "react";
+import { View, Dimensions } from "react-native";
+import { Timer } from "./Timer";
+import { SearchButton } from "./SearchButton";
+
+const sh = Dimensions.get('window').height
+
+export const TopBar = memo(function({seconds, setSeconds, started}:{seconds:number, setSeconds:Function, started:boolean}){
+ // console.log("rendering TopBar");
+ return (
+ <View style={{position:"absolute", top:"14%", width:"100%", padding:"2%", flex: 7, flexDirection:"row"}}>
+ <Timer seconds={seconds} setSeconds={setSeconds} started={started} />
+ <View style={{ flex: 7}}></View>
+ <SearchButton/>
+ </View>
+ );
+});
diff --git a/components/Home/ForYou/index.tsx b/components/Home/ForYou/index.tsx
new file mode 100644
index 0000000..c2fdc50
--- /dev/null
+++ b/components/Home/ForYou/index.tsx
@@ -0,0 +1,93 @@
+import { useState, useRef, memo, useEffect } from "react";
+import { View, ScrollView, Alert, Dimensions } from "react-native";
+import { QuestionType, fetch_questions } from "./qaFetching";
+import { QA_Panel } from "./QA_Panel";
+import { TopBar } from "./TopBar";
+import { SideButtons } from "./SideButtons";
+import { correct, wrong, time, skip, q_total } from "../../../App";
+
+const sh = Dimensions.get('window').height;
+
+export const ForYou = memo(function(){
+ //console.log("rendering ForYou");
+
+ let svr = useRef(null);
+ let iid = useRef(999999);
+ const [started, setStarted] = useState(false);
+ const [seconds, setSeconds] = useState(30);
+ const [qa, setQA]:[Array<QuestionType>,Function] = useState([]);
+ const [qIndex, setQIndex] = useState(0);
+ const [lastQIndex, setLastQIndex] = useState(0);
+ const [score, setScore] = useState(skip*q_total); // correct: +20 wrong: -20 skip: -10 full: 5*20=100
+ const [qAnswered, setQAnswered] = useState(0);
+
+ function test_ended(){
+ setStarted(false);
+ clearInterval(iid.current as any);
+ iid.current = null as any;
+ Alert.alert(`(Correct:+${correct}%. Wrong:${wrong}%. \nSkipped:${skip}%)`);
+ Alert.alert(`Your score for the last 5 MCQs is: ${score}%.`);
+ }
+
+ useEffect(()=>{
+ fetch_questions(q_total, setQA, qa.map(qq=>qq.id)); // load questions before user starts. removes repeated questions. may get less than 5 questions.
+ },[]);
+
+ useEffect(()=>{
+ if (started && qa.length > qIndex && (iid.current===null || iid.current===999999)) {
+ (svr.current as any).scrollTo({x:0, y:lastQIndex*sh, animate:true});
+ setQIndex(lastQIndex);
+ setLastQIndex(i=>(i+q_total));
+ setSeconds(time);
+ setScore(skip*q_total);
+ setQAnswered(0);
+ iid.current = setInterval(()=>{ // wait for questions to load first before starting countdown
+ setSeconds(s=>s-1);
+ },1000) as any;
+ } else if (!started){ // test stopped halfway
+ setQAnswered(99999);
+ }
+ if (started && qIndex+q_total > qa.length) fetch_questions(q_total, setQA, qa.map(qq=>qq.id)); // each test consists of 5 questions. at least 5 questions loaded.
+ },[started,qa,qIndex]);
+
+ useEffect(()=>{
+ if (qAnswered>=q_total) {
+ test_ended();
+ return;
+ }
+ if (seconds<1){
+ setSeconds(0); // in case negative
+ test_ended();
+ }
+ },[seconds]);
+
+ return (
+ <View style={{ flex: 1, backgroundColor: "black" }} >
+ <ScrollView ref={svr} style={{ height:qa.length*sh, opacity:(iid.current===999999)?0:1}} onScrollEndDrag={e=>{ // make view opaque as test starts
+ if ((e.nativeEvent.velocity as any).y < 0){
+ if (qIndex==qa.length) {
+ Alert.alert("No more question available...");
+ return;
+ }
+ if (qIndex+1==lastQIndex) {
+ (svr.current as any).scrollTo({x:0, y:(lastQIndex-1)*sh, animate:true}); // bounce back to normal position towards the very last screen
+ return;
+ }
+ (svr.current as any).scrollTo({x:0, y:(qIndex+1)*sh, animate:true});
+ setQIndex(i=>(i+1));
+
+ } else {
+ if (qIndex==0) return;
+ (svr.current as any).scrollTo({x:0, y:(qIndex-1)*sh, animate:true});
+ setQIndex(i=>(i-1));
+ }
+ }}>
+ {qa.map((q:QuestionType,index:number)=>(
+ <QA_Panel key={index} question={q} setScore={setScore} countScore={ (qIndex>=lastQIndex-q_total) } setQAnswered={ setQAnswered } />
+ ))}
+ </ScrollView>
+ <TopBar seconds={seconds} started={started} setSeconds={setSeconds} />
+ <SideButtons started={started} setStarted={setStarted} />
+ </View>
+ );
+});
diff --git a/components/Home/ForYou/qaFetching.tsx b/components/Home/ForYou/qaFetching.tsx
new file mode 100644
index 0000000..efa7ed2
--- /dev/null
+++ b/components/Home/ForYou/qaFetching.tsx
@@ -0,0 +1,87 @@
+export type AnswerType = {
+ id:string,
+ answer:string
+};
+
+export type QuestionType = {
+ id:number,
+ question:string,
+ answer:string,
+ description: string,
+ tag: string,
+ playlist: string,
+ unit: string,
+ user: {name: string, avatar:string},
+ image?: string,
+ options: AnswerType[]
+};
+
+function randomSwapA(arr:AnswerType[]){
+ let i:number = Math.floor(arr.length * Math.random());
+ let j:number = Math.floor(arr.length * Math.random());
+ let tmp:AnswerType = arr[i];
+ arr[i] = arr[j];
+ arr[j] = tmp;
+}
+
+function getQuestion():Promise<QuestionType>{
+ return new Promise((resolve,reject)=>{
+ fetch('https://cross-platform.rp.devfactory.com/for_you')
+ .then(response => response.json())
+ .then(json => {
+ for (let i=0; i<10; i++) randomSwapA(json.options); // randomize order of answer options
+ let d = json.description.split("#");
+ json.description = d[0];
+ json.tag = d[1];
+ json.unit = "Unit " + json.description.split(".")[0];
+ resolve(json);
+ })
+ .catch(error => {
+ console.error("ERROR:"+error);
+ reject(error);
+ });
+ });
+}
+
+function getAnswer(id:number):Promise<{id:number, correct_options:[{id:string}]}>{
+ return new Promise((resolve,reject)=>{
+ fetch(`https://cross-platform.rp.devfactory.com/reveal?id=${id}`)
+ .then(response => response.json())
+ .then(json => {
+ //console.log(id,json);
+ resolve(json);
+ })
+ .catch(error => {
+ console.error("ERROR:"+error);
+ reject(error);
+ });
+ });
+}
+
+async function fetchQA():Promise<QuestionType>{
+ let question:QuestionType = await getQuestion();
+ let answer:{id:number, correct_options:[{id:string}]}= await getAnswer(question.id);
+ question.answer = answer.correct_options[0].id;
+ return question;
+};
+
+async function fetchQA_batch(n:number):Promise<[QuestionType]>{
+ let qs:[QuestionType] = [] as any;
+ let qsp:[QuestionType] = [] as any;
+ for (let i=0; i<n; i++) qsp.push(fetchQA() as any);
+ let r = await Promise.all(qsp);
+ for (let qa of r){
+ if (!qs.map(q=>q.id).includes(qa.id)) qs.push(qa);
+ }
+ return qs;
+}
+
+export function fetch_questions(n:number, setQA:Function, qids:number[]){ // may add less than n questions due to repeated questions fetched, but at least one question added.
+ fetchQA_batch(n).then(q=>{
+ q = q.filter(qq=>(!qids.includes(qq.id))) as [QuestionType]; // excludes repeated questions
+ if (q.length == 0 as number) fetch_questions(n, setQA, qids); // refetch questions if no new question fetched
+ else {
+ setQA((qa:any)=>[...qa, ...q]);
+ }
+ });
+}
\ No newline at end of file
diff --git a/components/Home/index.tsx b/components/Home/index.tsx
new file mode 100644
index 0000000..436472b
--- /dev/null
+++ b/components/Home/index.tsx
@@ -0,0 +1,8 @@
+import { ForYou } from './ForYou';
+import HorizontalNavigator from "../shared/HorizontalNavigator";
+
+export default function Home(){
+ return (
+ <HorizontalNavigator screens = {[["For You",ForYou]]} />
+ );
+}
\ No newline at end of file
diff --git a/components/Profile/index.tsx b/components/Profile/index.tsx
new file mode 100644
index 0000000..b7acc7c
--- /dev/null
+++ b/components/Profile/index.tsx
@@ -0,0 +1,9 @@
+import { View, Text } from "react-native";
+
+export default function Profile(){
+ return (
+ <View style={{flex:1, backgroundColor:"black", paddingVertical:"30%"}}>
+ <Text style={{fontSize:50, color:"white"}}>Profile</Text>
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/HorizontalNavigator.tsx b/components/shared/HorizontalNavigator.tsx
new file mode 100644
index 0000000..ec1f39f
--- /dev/null
+++ b/components/shared/HorizontalNavigator.tsx
@@ -0,0 +1,42 @@
+import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
+
+const Tab = createMaterialTopTabNavigator();
+
+export default function HorizontalNavigator({screens}:any){
+ let scount = screens.length;
+ return (
+ <Tab.Navigator
+ screenOptions={{
+ tabBarLabelStyle: {
+ textTransform: "none",
+ fontWeight: "bold",
+ marginBottom: "-1%"
+ },
+ tabBarActiveTintColor:"white",
+ tabBarInactiveTintColor:"grey",
+ tabBarStyle: {
+ backgroundColor: 'transparent',
+ position: 'absolute',
+ top: "5%",
+ left: 0,
+ right: 0,
+ elevation: 0,
+ },
+ tabBarIndicatorStyle:{
+ backgroundColor: "white",
+ height: "8%",
+ width: "10%",
+ marginLeft : `${((100/scount)-10)/2}%`,
+ marginRight : `${-((100/scount)-10)/2}%`,
+ borderTopLeftRadius : 15,
+ borderBottomLeftRadius : 15,
+ borderTopRightRadius : 15,
+ borderBottomRightRadius : 15
+ }
+
+ }}
+ >
+ {screens.map((s:[name:string, component:any]) => <Tab.Screen name={s[0]} component={s[1]} key={s[0]} />)}
+ </Tab.Navigator>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/Modal.tsx b/components/shared/Modal.tsx
new file mode 100644
index 0000000..e69de29
diff --git a/components/shared/OutlineText.tsx b/components/shared/OutlineText.tsx
new file mode 100644
index 0000000..0b18094
--- /dev/null
+++ b/components/shared/OutlineText.tsx
@@ -0,0 +1,67 @@
+import { View, StyleSheet, Dimensions } from "react-native";
+import { Children, cloneElement, isValidElement } from "react";
+
+const sh = Dimensions.get('window').height
+
+type Props = {
+ children: any,
+ color: string,
+ stroke: number,
+ backgroundColor: string
+}
+
+export function OutlineText (props:Props) {
+ const createClones = (w: number, h: number, color?: string) => {
+ const { children } = props;
+ return Children.map(children, child => {
+ if (isValidElement(child)) {
+ const currentProps = child.props as any;
+ const currentStyle = currentProps ? (currentProps.style || {}) : {};
+ const newProps = {
+ ...currentProps,
+ style: {
+ ...currentStyle,
+ textShadowOffset: {
+ width: w,
+ height: h
+ },
+ textShadowColor: color,
+ textShadowRadius: 1
+ }
+ }
+ return cloneElement(child, newProps)
+ }
+ return child;
+ });
+ }
+ const {color, stroke, backgroundColor, children} = props;
+ const strokeW = stroke;
+ const top = createClones(0, -strokeW * 1.2, color);
+ const topLeft = createClones(-strokeW, -strokeW, color);
+ const topRight = createClones(strokeW, -strokeW, color);
+ const right = createClones(strokeW, 0, color);
+ const bottom = createClones(0, strokeW, color);
+ const bottomLeft = createClones(-strokeW, strokeW, color);
+ const bottomRight = createClones(strokeW, strokeW, color);
+ const left = createClones(-strokeW * 1.2, 0, color);
+