aboutsummaryrefslogtreecommitdiff
path: root/src/actions/firebaseStorage.js
blob: af114f1fcfdca623ddd17572d742fba42c82a72e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { storage } from '../firebase.js';

export const UPDATE_PICTURE = 'UPDATE_PICTURE';

export const uploadPicture = (file, uploader) => (dispatch, getState) => {
    if(file) {
      var storageRef  =   storage.ref('requests/' + getState().firebaseAuth.uid + '/' + file.name);

      var task = storageRef.put(file);
    
      task.on('state_changed', function(snapshot) {
        var percentage  = (snapshot.bytesTransferred /
        snapshot.totalBytes) * 100;
        uploader.value  = percentage;
      });

      dispatch(updatePicture(file.name));
    }
}

export const updatePicture = (_name) => {
    return {
        type:       'UPDATE_PICTURE',
        name:       _name,
        uploaded:   true
    }
}