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.js62
1 files changed, 60 insertions, 2 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js
index 85ebe20..fe3ddb0 100644
--- a/src/actions/firebase.js
+++ b/src/actions/firebase.js
@@ -21,6 +21,7 @@ export const signIn = (_email, _password) => (dispatch) => {
*/
dispatch(authSuccess(user));
dispatch(getHours())
+ dispatch(pullRegisteredCompetitions());
})
.catch((error) => {
dispatch(authFail(error.code));
@@ -64,8 +65,8 @@ export const authSignOut = () => {
//End Firebase Auth
//Start Firebase Firestore
-export const GET_HOURS = 'GET_HOURS';
-export const UPDATE_HOURS = 'UPDATE_HOURS'
+export const GET_HOURS = 'GET_HOURS';
+export const UPDATE_HOURS = 'UPDATE_HOURS';
export const getHours = () => (dispatch, getState) => {
const currentState = getState().firebase;
@@ -87,4 +88,61 @@ export const updateHours = (hours) => {
}
}
+export const REGISTER_COMP = 'REGISTER_COMP';
+export const PULL_REGISTERED_COMPETITIONS = 'PULL_REGISTERED_COMPETITIONS';
+export const UPDATE_REGISTERED_COMPETITIONS = 'UPDATE_REGISTERED_COMPETITIONS';
+
+export const registerComp = (compName) => (dispatch, getState) => {
+ var docRef = firestore.collection('competitions').doc(compName);
+ var uid = getState().firebase.uid;
+
+ 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 = [];
+
+ var docRef = firestore.collection('competitions');
+ docRef.get().then((query) => {
+ query.forEach((doc) => {
+ if(doc.data().uids.includes(getState().firebase.uid)) {
+ registeredComps.push(doc.id);
+ }
+ })
+ });
+
+ dispatch(updateRegisteredCompetitions(registeredComps));
+}
+
+
+
+
+export const updateRegisteredCompetitions = (registeredComps) => {
+ return {
+ type: UPDATE_REGISTERED_COMPETITIONS,
+ payload: registeredComps
+ }
+}
+
+
+
+
//End Firebase Firestore