-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeScreen.js
More file actions
177 lines (157 loc) · 6.16 KB
/
Copy pathHomeScreen.js
File metadata and controls
177 lines (157 loc) · 6.16 KB
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
import { View, Text, StyleSheet, ScrollView, FlatList, TouchableOpacity, Animated, Easing, Image, Alert } from 'react-native'
import React, { useEffect, useState } from 'react'
import { SafeAreaView } from 'react-native-safe-area-context';
import CountDown from 'react-native-countdown-component';
import axios from 'axios';
const HomeScreen = () => {
const [Contests, setContests] = useState([]);
const [triggerChange, setTriggerChange] = useState('')
const [elapsedTime, setElapsedTime] = useState(0);
const [finalContestsList, setfinalContestsList] = useState([])
const [isLoader, setisLoader] = useState(false)
const API_URL = 'https://codeforces.com/api/contest.list';
const getUpcomingContests = async () => {
setisLoader(true)
try {
const response = await axios.get(API_URL, {
params: {
apiKey: '',
gym: false, // only get non-gym contests
phase: 'BEFORE', // only get contests that haven't started yet
},
});
const contests = response.data.result;
const upcomingContests = contests.filter((contest) => contest.phase === 'BEFORE');
setisLoader(false)
return upcomingContests;
} catch (error) {
console.error(error);
setisLoader(false)
return [];
}
};
useEffect(() => {
getUpcomingContests().then((upcomingContests) => {
setContests(upcomingContests);
});
}, []);
useEffect(() => {
const sortedContests = Contests.sort((a, b) => a.startTimeSeconds - b.startTimeSeconds);
setfinalContestsList(sortedContests)
}, [Contests])
const renderContests = ({ item , index }) => {
let cardColor;
let statusColor;
switch (item.status) {
case 'New':
item.statusColor = 'blue';
break;
case 'Urgent':
item.statusColor = 'orange';
break;
case 'ready':
item.statusColor = 'green';
break;
case 'Time Over':
item.statusColor = 'black';
default:
statusColor = 'black';
}
const handleTimerFinish = () => {
if(item.status != 'Ready For Pickup'){
item.status = '⚠️ Time Over';
item.statusColor = 'white'
item.color = '#fa5050'
//setTriggerChange(Math.random()*10)
}
};
const handleCompleted = (itemId,index) =>{
const updatedContests = Contests.filter((item) => item.id !== itemId);
setContests(updatedContests)
}
const now = new Date();
const utcSeconds = Math.floor(now.getTime() / 1000);
return (
<TouchableOpacity style={{backgroundColor: item.color? item.color :'white',padding: 10,marginBottom: 10,borderRadius:20,height:170}}>
<View style={{flexDirection:'row',marginBottom:10}}>
<Text style={styles.ContestsName}>{item.name}</Text>
{/* {item.showDelivery ?
<Image
style={{ height:40,width:40,left:'20%' }}
source={require('../assets/delivery-bike.png')}
/> :null} */}
</View>
<View style={{alignContent:'flex-end'}}>
</View>
<View style={{flexDirection:'row'}}>
<Text style={{color:'black',marginRight:10,fontWeight:'bold'}}>Time Left : </Text>
<View>
<CountDown
until={item.startTimeSeconds - utcSeconds}
onFinish={handleTimerFinish}
digitStyle={{backgroundColor: '#FAB913', Width: 2, Color: '#000000'}}
digitTxtStyle={{color: 'black'}}
onPress={() => Alert.alert("Kyu ungli kar ra hai","Upsolve hi kar le \n tab tak")}
// onChange = { ()=> {
// if(item.status != '❗Expiring Soon' && item.status != 'Ready For Pickup' && (item.time*60 - elapsedTime)<=300 && (item.time*60 - elapsedTime)>100){
// console.log(item.name)
// item.status = '❗Expiring Soon'
// item.statusColor = 'white'
// item.color = '#db934f'
// setTriggerChange(Math.random()*10)
// }
// }}
size={15}
timeToShow={['D','H', 'M', 'S']}
showSeparator
/>
</View>
</View>
<View >
<Text style={{color:item.statusColor? item.statusColor : 'black',alignItems:'flex-start',fontWeight:'bold'}}>Duration : {item.durationSeconds / (60*60)} Hours</Text>
</View>
</TouchableOpacity>
);
}
return (
<ScrollView style={styles.container}>
<Text style={{alignSelf:'center',fontSize:30,fontWeight:'bold',margin:20,marginBottom:50,color:'white'}}> Welcome !</Text>
<FlatList
data={finalContestsList}
keyExtractor={(item,index) => item.id}
renderItem={renderContests}
/>
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000000',
padding: 10,
},
ContestsContainer: {
backgroundColor: '#f2f2f2',
padding: 10,
marginBottom: 10,
bContestsRadius:20,
height:170
},
ContestsName: {
fontWeight: 'bold',
fontSize: 18,
color:'#000000',
marginBottom: 5,
marginLeft:5
},
ContestsTime: {
fontSize: 14,
marginBottom: 5,
color:'#001123'
},
ContestsStatus: {
fontSize: 14,
color:'green'
}
});
export default HomeScreen