forked from AkshayWarrier/Volunteer-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrganizationFeed.js
144 lines (125 loc) · 4.16 KB
/
OrganizationFeed.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
import { StyleSheet, Text, View, ScrollView, TouchableOpacity,RefreshControl } from 'react-native';
import {TaskCard} from './TaskCard';
import { getDocs,collection } from "firebase/firestore";
import { db} from "./config.js";
import {auth,query_db,organisations_collection} from './methods'
import Icon from 'react-native-vector-icons/FontAwesome';
import { useState, useEffect,useCallback } from 'react';
async function getTasksInfo(){
try{
let task_data = [];
const querySnapshot = await getDocs(collection(db, "tasks"));
querySnapshot.forEach(async (doc) => {
// doc.data() is never undefined for query doc snapshots
task_data.push(doc.data());
});
return task_data;
}catch(e){
console.log(e);
}
}
let tasks = [];
const wait = (timeout) => {
return new Promise(resolve => {
setTimeout(resolve, timeout);
});
}
export const OrganizationFeed = ({navigation,userEmail}) => {
const [refreshing, setRefreshing] = useState(false);
const onRefresh = useCallback(() => {
setRefreshing(true);
wait(2000).then(() => setRefreshing(false));
}, []);
const getOrgIDfromEmail = async (email) => {
let orgID = "";
await query_db("Email","==",email,organisations_collection).then((querySnapshot) => {
querySnapshot.forEach((doc) => {
orgID = doc.data().OrgID;
});
});
return orgID;
}
const [taskData, setTaskData] = useState([]);
useEffect(() => {(async() =>{
try {
let task_data = [];
let orgID = await getOrgIDfromEmail(userEmail);
const querySnapshot = getDocs(collection(db, "tasks"))
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
if(doc.data().OrgID == orgID){
task_data.push(doc.data());
}
});
let data = task_data;
setTaskData(data);
});
} catch (error) {
console.log(error);
}
})();
}, [refreshing]);
return (
<View style={styles.screen}>
<ScrollView
style={styles.container}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
>
{taskData.map((task, index) => {
return (
<TaskCard key={index} name={task.Name} organisation={task.OrgName} type={task.Tag} remote={task.Remote} location={task.City.label + ', ' + task.State.label} description={task["Job Description"]} startDate={task["Start Date"]} formLink={task["FormLink"]} volunteersCount={task["Volunteers Registered"]} volunteersReq={task.volunteersReq} taskID={task["Task ID"]} />
)
})}
</ScrollView>
<TouchableOpacity style={styles.button} onPress={() => navigation.navigate('CreateTaskForm',{setRefreshing:{setRefreshing}})}>
<Icon name="plus" style={styles.icon}/>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
},
container: {
flex: 1,
backgroundColor: "#F7FFF7",
padding: 10,
},
button: {
position: 'absolute',
bottom: 30,
right: 30,
width: 60,
height: 60,
backgroundColor: "#F7FFF7",
color: "#1A535C",
borderRadius: 50,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 12,
},
shadowOpacity: 0.58,
elevation: 10,
},
icon: {
fontSize: 30,
color: "#1A535C",
textAlign: 'center',
textAlignVertical: 'center',
height: 60,
},
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 20,
fontWeight: 'bold',
color: '#1A535C',
},
});