diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/firebaseAdmin.js | 2 | ||||
-rw-r--r-- | src/actions/firebaseAuth.js | 39 | ||||
-rw-r--r-- | src/actions/firebaseFirestore.js | 33 |
3 files changed, 23 insertions, 51 deletions
diff --git a/src/actions/firebaseAdmin.js b/src/actions/firebaseAdmin.js index 8fdc8fa..4a00833 100644 --- a/src/actions/firebaseAdmin.js +++ b/src/actions/firebaseAdmin.js @@ -82,7 +82,7 @@ export const adminDeleteRequest = (_id) => (dispatch) => { //User triggered events dispatching to middleware -export const adminListener = () => (dispatch, getState) => { +export const adminListener = () => (dispatch) => { document.onkeyup = function(e) { if(e.altKey && e.which == 65) { var docRef = firestore.collection('keys').doc('adminKey'); diff --git a/src/actions/firebaseAuth.js b/src/actions/firebaseAuth.js index 720a172..ff49888 100644 --- a/src/actions/firebaseAuth.js +++ b/src/actions/firebaseAuth.js @@ -79,42 +79,3 @@ export const signOut = () => (dispatch) => { dispatch(authSignOut()); }); } - -//other - -export const setUserData = (_divison) => (dispatch, getState) => { - const uid = getState().firebase.uid; - var docRef = firestore.collection('users').doc(uid); - docRef.set({ - hours: 0, - divison: _divison - }).catch((error) => { - console.log(error); - }) -} - -export const adminListener = () => (dispatch, getState) => { - document.onkeyup = function(e) { - if(e.altKey && e.which == 65) { - var docRef = firestore.collection('keys').doc('adminKey'); - docRef.get().then((doc) => { - if(prompt('Enter admin password') == doc.data().password) { - dispatch(adminControls()); - } - }); - } - } -} - -export const adminControls = () => (dispatch) => { - dispatch(updateAdmin()); - dispatch(snapshotAdminRequests()); - dispatch(snapshotAdminCompList()); -} - -export const updateAdmin = () => { - return { - type: UPDATE_ADMIN, - payload: true - } -} diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js index 8cfb0da..5489b5b 100644 --- a/src/actions/firebaseFirestore.js +++ b/src/actions/firebaseFirestore.js @@ -3,7 +3,7 @@ import { firestore } from '../firebase.js'; export const UPDATE_DIVISON = 'UPDATE_DIVISON'; export const UPDATE_HOURS = 'UPDATE_HOURS'; export const UPDATE_REGISTERED_COMPETITIONS = 'UPDATE_REGISTERED_COMPETITIONS'; -export const UPDATE_FORUM_POSTS = 'UPDATE_FORUM_POSTS'; +export const UPDATE_FORUM_POSTS = 'UPDATE_FORUM_POSTS'; export const updateDivison = (divison) => { return { @@ -45,11 +45,11 @@ export const fetchDivison = () => (dispatch, getState) => { } export const snapshotHours = () => (dispatch, getState) => { - const currentState = getState().firebase; - if(currentState.initialized) { + const currentAuthState = getState().firebaseAuth; + if(currentAuthState.signedIn) { var totalHours; - var docRefUsers = firestore.collection('users').doc(currentState.uid); - var docRefReq = firestore.collection('requests').where('uid', '==', currentState.uid); + var docRefUsers = firestore.collection('users').doc(currentAuthState.uid); + var docRefReq = firestore.collection('requests').where('uid', '==', currentAuthState.uid); docRefUsers.onSnapshot((doc) => { totalHours = doc.data().hours; docRefReq.onSnapshot((query) => { @@ -68,7 +68,7 @@ export const snapshotRegisteredCompetitions = () => (dispatch, getState) => { docRef.onSnapshot((querySnapshot) => { var registeredComps = []; querySnapshot.forEach((doc) => { - if(doc.exists && doc.data().uids.includes(getState().firebase.uid)) { + if(doc.exists && doc.data().uids.includes(getState().firebaseAuth.uid)) { registeredComps.push(doc.id); } }); @@ -89,10 +89,21 @@ export const snapshotForums = () => (dispatch) => { //Do not dipatch to store, only update firebaseFirestore +export const setUserData = (_divison) => (dispatch, getState) => { + const uid = getState().firebaseAuth.uid; + var docRef = firestore.collection('users').doc(uid); + docRef.set({ + hours: 0, + divison: _divison + }).catch((error) => { + console.log(error); + }) +} + export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => { var docRef = firestore.collection('requests'); - const _uid = getState().firebase.uid; - const _email = getState().firebase.userEmail; + const _uid = getState().firebaseAuth.uid; + const _email = getState().firebaseAuth.userEmail; docRef.add({ time: _time, trainee: _trainee, @@ -104,8 +115,8 @@ export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => export const registerComp = (compName) => (dispatch, getState) => { var docRef = firestore.collection('competitions').doc(compName); - var uid = getState().firebase.uid; - var email = getState().firebase.userEmail; + var uid = getState().firebaseAuth.uid; + var email = getState().firebaseAuth.userEmail; docRef.get().then((doc) => { if(doc.exists) { var uidArr = doc.data().uids; @@ -128,7 +139,7 @@ export const registerComp = (compName) => (dispatch, getState) => { export const createForumPost = (_subject, _content) => (dispatch, getState) => { var docRef = firestore.collection('posts'); - const userEmail = getState().firebase.userEmail; + const userEmail = getState().firebaseAuth.userEmail; docRef.add({ email: userEmail, subject: _subject, |