diff options
| author | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-19 03:02:16 -0400 |
|---|---|---|
| committer | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-19 03:02:16 -0400 |
| commit | 98b0aa1092d8b46b621a7d9d2772aa972d6957b6 (patch) | |
| tree | 3d37eb06889e0a7bf8ad92fe4bf091e6d24bc8a6 /src/actions | |
| parent | 6603b409b2a712a48c3611782de560f442f8b241 (diff) | |
Made the website more interactive by adding alerts on successful and failed attempts when connecting to database. Also, dealt a bit with offline functionality.
Diffstat (limited to 'src/actions')
| -rw-r--r-- | src/actions/firebaseFirestore.js | 129 | ||||
| -rw-r--r-- | src/actions/firebaseStorage.js | 28 |
2 files changed, 99 insertions, 58 deletions
diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js index 7e65eec..701a0c3 100644 --- a/src/actions/firebaseFirestore.js +++ b/src/actions/firebaseFirestore.js @@ -44,6 +44,7 @@ export const fetchDivison = () => (dispatch, getState) => { }); } +var isAdminUpdate = false; export const snapshotHours = () => (dispatch, getState) => { const currentAuthState = getState().firebaseAuth; if(currentAuthState.signedIn) { @@ -53,11 +54,15 @@ export const snapshotHours = () => (dispatch, getState) => { docRefUsers.onSnapshot((doc) => { totalHours = doc.data().hours; docRefReq.onSnapshot((query) => { + if(isAdminUpdate) { + alert("One of your hours requests has been approved or denied.\nGo to dashboard to see changes.") + } var requestedHours = 0; query.forEach((docs) => { requestedHours += docs.data().time; }); dispatch(updateHours(totalHours, requestedHours)); + isAdminUpdate = true; }); }); } @@ -101,58 +106,90 @@ export const setUserData = (_divison) => (dispatch, getState) => { } export const requestHours = (_time, _trainee, _location, _subject, _date, _pictureName) => (dispatch, getState) => { - var docRef = firestore.collection('requests'); - const _uid = getState().firebaseAuth.uid; - const _email = getState().firebaseAuth.userEmail; - const _path = 'requests/' + _uid + '/' + _pictureName; - - var fireStorageRef = fireStorage.ref().child(_path); - fireStorageRef.getDownloadURL().then((url) => { - docRef.add({ - time: _time, - trainee: _trainee, - location: _location, - subject: _subject, - day: _date, - imgUrl: url, - path: _path, - uid: _uid, - email: _email + if(getState().app.offline) { + alert("Failed to create forum post. Must have internet connection.") + } else { + isAdminUpdate = false; + var docRef = firestore.collection('requests'); + const _uid = getState().firebaseAuth.uid; + const _email = getState().firebaseAuth.userEmail; + const _path = 'requests/' + _uid + '/' + _pictureName; + + var fireStorageRef = fireStorage.ref().child(_path); + fireStorageRef.getDownloadURL().then((url) => { + docRef.add({ + time: _time, + trainee: _trainee, + location: _location, + subject: _subject, + day: _date, + imgUrl: url, + path: _path, + uid: _uid, + email: _email + }).then(()=> { + alert("Successfuly sent hours request for " + _time*60 + " minutes.\n" + + "If it is approved, it will update on your dashboard."); + }).catch((error) => { + alert(error); + }); }); - }); - + } } export const registerComp = (compName) => (dispatch, getState) => { - var docRef = firestore.collection('competitions').doc(compName); - var uid = getState().firebaseAuth.uid; - var email = getState().firebaseAuth.userEmail; - docRef.get().then((doc) => { - if(doc.exists) { - var uidArr = doc.data().uids; - var emailArr = doc.data().emails; - uidArr.push(uid); - emailArr.push(email); - docRef.set({ - uids: uidArr, - emails: emailArr - }); - } else { - docRef.set({ - uids : [uid], - emails: [email] - }); - } - }); + if(getState().app.offline) { + alert("Failed to register. Please establish internet connection.") + } else { + var docRef = firestore.collection('competitions').doc(compName); + var uid = getState().firebaseAuth.uid; + var email = getState().firebaseAuth.userEmail; + docRef.get().then((doc) => { + if(doc.exists) { + var uidArr = doc.data().uids; + var emailArr = doc.data().emails; + uidArr.push(uid); + emailArr.push(email); + docRef.set({ + uids: uidArr, + emails: emailArr + }).then(()=> { + alert("Successfuly registered for " + compName + "."); + }).catch((error) => { + alert(error); + }); + } else { + docRef.set({ + uids : [uid], + emails: [email] + }).then(()=> { + alert("Successfuly registered for " + compName + "."); + }).catch((error) => { + alert(error); + }); + } + }).catch((error) => { + alert(error); + }); + } } export const createForumPost = (_subject, _content) => (dispatch, getState) => { - var docRef = firestore.collection('posts'); - const userEmail = getState().firebaseAuth.userEmail; - docRef.add({ - email: userEmail, - subject: _subject, - content: _content - }); + if(getState().app.offline) { + alert("Failed to create forum post. Please establish internet connection.") + } else { + var docRef = firestore.collection('posts'); + const userEmail = getState().firebaseAuth.userEmail; + docRef.add({ + email: userEmail, + subject: _subject, + content: _content + }).then(()=> { + alert("Successfuly posted forum with subject " + _subject + "."); + }).catch((error) => { + alert(error); + }); + } + } diff --git a/src/actions/firebaseStorage.js b/src/actions/firebaseStorage.js index 6828344..ad158f8 100644 --- a/src/actions/firebaseStorage.js +++ b/src/actions/firebaseStorage.js @@ -3,18 +3,22 @@ import { fireStorage } from '../firebase.js'; export const UPDATE_PICTURE = 'UPDATE_PICTURE'; export const uploadPicture = (file, uploader) => (dispatch, getState) => { - if(file) { - var fireStorageRef = fireStorage.ref('requests/' + getState().firebaseAuth.uid + '/' + file.name); - - var task = fireStorageRef.put(file); - - task.on('state_changed', function(snapshot) { - var percentage = (snapshot.bytesTransferred / - snapshot.totalBytes) * 100; - uploader.value = percentage; - }); - - dispatch(updatePicture(file.name)); + if(getState().app.offline) { + alert("Failed to upload image.\t Please establish internet connection and retry to upload photo.") + } else { + if(file) { + var fireStorageRef = fireStorage.ref('requests/' + getState().firebaseAuth.uid + '/' + file.name); + + var task = fireStorageRef.put(file); + + task.on('state_changed', function(snapshot) { + var percentage = (snapshot.bytesTransferred / + snapshot.totalBytes) * 100; + uploader.value = percentage; + }); + + dispatch(updatePicture(file.name)); + } } } |
