aboutsummaryrefslogtreecommitdiff
path: root/src/actions/firebase.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions/firebase.js')
-rw-r--r--src/actions/firebase.js39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js
index ab2e28e..2599d4f 100644
--- a/src/actions/firebase.js
+++ b/src/actions/firebase.js
@@ -21,7 +21,7 @@ export const signIn = (_email, _password) => (dispatch) => {
*/
dispatch(authSuccess(user));
dispatch(getHours())
- dispatch(pullRegisteredCompetitions());
+ dispatch(snapshotRegisteredCompetitions());
})
.catch((error) => {
dispatch(authFail(error.code));
@@ -77,8 +77,6 @@ export const getHours = () => (dispatch, getState) => {
dispatch(updateHours(doc.data().hours, doc.data().requestedHours));
});
}
-
-
}
export const updateHours = (hours, reqHours) => {
@@ -100,42 +98,34 @@ export const registerComp = (compName) => (dispatch, getState) => {
docRef.get().then((doc) => {
if(doc.exists) {
var uidArr = doc.data().uids;
-
uidArr.push(uid);
docRef.set({
uids: uidArr
});
-
- dispatch(pullRegisteredCompetitions());
} else {
docRef.set({
uids : [uid]
- }).then(() => {
- dispatch(pullRegisteredCompetitions());
});
}
});
}
-export const pullRegisteredCompetitions = () => (dispatch, getState) =>{
- var registeredComps = [];
+export const snapshotRegisteredCompetitions = () => (dispatch, getState) =>{
var docRef = firestore.collection('competitions');
- docRef.get().then((query) => {
- query.forEach((doc) => {
- if(doc.data().uids.includes(getState().firebase.uid)) {
+ docRef.onSnapshot((querySnapshot) => {
+ var registeredComps = [];
+ querySnapshot.forEach((doc) => {
+ if(doc.exists && doc.data().uids.includes(getState().firebase.uid)) {
registeredComps.push(doc.id);
}
- })
- });
+ });
+ dispatch(updateRegisteredCompetitions(registeredComps));
- dispatch(updateRegisteredCompetitions(registeredComps));
+ });
}
-
-
-
export const updateRegisteredCompetitions = (registeredComps) => {
return {
type: UPDATE_REGISTERED_COMPETITIONS,
@@ -143,7 +133,18 @@ export const updateRegisteredCompetitions = (registeredComps) => {
}
}
+export const REQUEST_HOURS = 'REQUEST_HOURS';
+export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => {
+ var docRef = firestore.collection('requests');
+ var _uid = getState().firebase.uid;
+ docRef.add({
+ time: _time,
+ trainee: _trainee,
+ date: _date,
+ uid: _uid
+ });
+}
//End Firebase Firestore