aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foiani <mfoiani2019@communiyschoolnaples.org>2018-08-13 16:47:34 -0400
committerMichael Foiani <mfoiani2019@communiyschoolnaples.org>2018-08-13 16:47:34 -0400
commit717352f8653a71eba003ec33dfa6355463208045 (patch)
tree62ec6ae72a58d4ab80565e2f4b9cf6b20fb9654f
parent3c96bc3f51a97b13c76db305502436d54cc35a6b (diff)
Now deletes img from storage after use. Done with basic img backend stuff.
-rw-r--r--src/actions/firebaseAdmin.js16
-rw-r--r--src/actions/firebaseFirestore.js6
-rw-r--r--src/components/mao-admin.js3
-rw-r--r--src/components/request-element.js11
4 files changed, 23 insertions, 13 deletions
diff --git a/src/actions/firebaseAdmin.js b/src/actions/firebaseAdmin.js
index 4b64cbf..5ca0d17 100644
--- a/src/actions/firebaseAdmin.js
+++ b/src/actions/firebaseAdmin.js
@@ -1,4 +1,4 @@
-import { firestore } from '../firebase.js';
+import { firestore, storage } from '../firebase.js';
export const UPDATE_ADMIN = 'UPDATE_ADMIN';
export const UPDATE_ADMIN_REQUESTS = 'UPDATE_ADMIN_REQUESTS';
@@ -69,14 +69,16 @@ export const snapshotAdminCompList = () => (dispatch) => {
});
}
-export const adminRejectHours = (_id) => (dispatch) => {
- dispatch(adminDeleteRequest(_id));
+export const adminRejectHours = (_id, _path) => (dispatch) => {
+ dispatch(adminDeleteRequest(_id, _path));
}
-export const adminDeleteRequest = (_id) => (dispatch) => {
+export const adminDeleteRequest = (_id, _path) => (dispatch) => {
var docRef = firestore.collection('requests').doc(_id);
docRef.delete().then(() => {
- //Delete associated picture
+ var storageRef = storage.ref().child(_path);
+ storageRef.delete().then(() => {
+ });
});
}
@@ -95,7 +97,7 @@ export const adminListener = () => (dispatch) => {
}
}
-export const adminApproveHours = (_uid, _time, _id) => (dispatch) => {
+export const adminApproveHours = (_uid, _time, _id, _path) => (dispatch) => {
var docRef = firestore.collection('users').doc(_uid);
docRef.get().then((doc) => {
if(doc.exists) {
@@ -106,5 +108,5 @@ export const adminApproveHours = (_uid, _time, _id) => (dispatch) => {
});
}
});
- dispatch(adminDeleteRequest(_id));
+ dispatch(adminDeleteRequest(_id, _path));
}
diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js
index 6ce8492..a95e0c8 100644
--- a/src/actions/firebaseFirestore.js
+++ b/src/actions/firebaseFirestore.js
@@ -104,8 +104,9 @@ export const requestHours = (_time, _trainee, _location, _subject, _date, _pictu
var docRef = firestore.collection('requests');
const _uid = getState().firebaseAuth.uid;
const _email = getState().firebaseAuth.userEmail;
+ const _path = 'requests/' + _uid + '/' + _pictureName;
- var storageRef = storage.ref().child('requests/' + _uid + '/' + _pictureName);
+ var storageRef = storage.ref().child(_path);
storageRef.getDownloadURL().then((url) => {
docRef.add({
time: _time,
@@ -113,7 +114,8 @@ export const requestHours = (_time, _trainee, _location, _subject, _date, _pictu
location: _location,
subject: _subject,
day: _date,
- imgPath: url,
+ imgUrl: url,
+ path: _path,
uid: _uid,
email: _email
});
diff --git a/src/components/mao-admin.js b/src/components/mao-admin.js
index ffdcb19..7047cab 100644
--- a/src/components/mao-admin.js
+++ b/src/components/mao-admin.js
@@ -168,7 +168,8 @@ class MaoAdmin extends connect(store)(PageViewElement) {
requestElement.subject = this.requests[i].subject;
requestElement.uid = this.requests[i].uid;
requestElement.docId = this.requests[i].docId;
- requestElement.imgPath = this.requests[i].imgPath;
+ requestElement.imgUrl = this.requests[i].imgUrl;
+ requestElement.imgPath = this.requests[i].path;
requestGrid.appendChild(requestElement);
}
diff --git a/src/components/request-element.js b/src/components/request-element.js
index 37f6feb..c01b34e 100644
--- a/src/components/request-element.js
+++ b/src/components/request-element.js
@@ -68,10 +68,13 @@ class RequestElement extends connect(store)(LitElement) {
on-tap= "${() => this.rejectHours()}">
Reject Time
</paper-button>
+
+ <hr/>
+
<iron-image
style:"width:100%; height:auto;"
preload
- src="${props.imgPath}">
+ src="${props.imgUrl}">
</iron-image>
</div>
</paper-card>
@@ -87,6 +90,7 @@ class RequestElement extends connect(store)(LitElement) {
subject: String,
uid: String,
id: String,
+ imgUrl: String,
imgPath: String,
infoTabOpen: Boolean
@@ -103,6 +107,7 @@ class RequestElement extends connect(store)(LitElement) {
this.subject = "Unknown subject";
this.uid = "Unknown uid";
this.docId = "Unknown docId";
+ this.imgUrl = ""
this.imgPath = "";
this.infoTabOpen = false;
@@ -118,13 +123,13 @@ class RequestElement extends connect(store)(LitElement) {
approveHours() {
if(confirm('Are you sure you want to APPROVE ' + (this.time*60) + ' minutes for ' + this.email +' ?')) {
- store.dispatch(adminApproveHours(this.uid, this.time, this.docId));
+ store.dispatch(adminApproveHours(this.uid, this.time, this.docId, this.imgPath));
}
}
rejectHours() {
if(confirm('Are you sure you want to REJECT ' + (this.time*60) + ' minutes for ' + this.email +' ?')) {
- store.dispatch(adminRejectHours(this.docId));
+ store.dispatch(adminRejectHours(this.docId, this.imgPath));
}
}