diff options
| author | Michael Foiani <sotech117@michaels-mbp.lan> | 2018-07-29 01:52:47 -0400 |
|---|---|---|
| committer | Michael Foiani <sotech117@michaels-mbp.lan> | 2018-07-29 01:52:47 -0400 |
| commit | eaf489da66c51cce931bceccd569d76704b205f9 (patch) | |
| tree | 07f14fa30540243134ae4b209b474b3e4db36453 /src/actions/firebase.js | |
| parent | eb948ad14ddd58e483bd8545c1fca64f50ddb648 (diff) | |
Created backend for tutoring hour requests. Also, fixed some bugs on competition page by using snapshots.
Diffstat (limited to 'src/actions/firebase.js')
| -rw-r--r-- | src/actions/firebase.js | 39 |
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 |
