Repository navigation
Expand file tree
/
Copy pathservices.js
More file actions
63 lines (57 loc) · 1.39 KB
/
Copy pathservices.js
File metadata and controls
63 lines (57 loc) · 1.39 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as firebase from 'firebase';
import 'firebase/firestore';
import { SET_MUSIC, ADD_MUSIC } from './actions';
// Initialize Firebase
const firebaseConfig = {
apiKey: 'AIzaSyCaHkSQGdyvtyTEK-Ys2AjpKuhDu0rxegw',
authDomain: 'mycollctor.firebaseapp.com',
databaseURL: 'https://mycollctor.firebaseio.com',
projectId: 'mycollctor',
storageBucket: 'mycollctor.appspot.com',
messagingSenderId: '198939433139'
};
firebase.initializeApp(firebaseConfig);
function handleResponse(response) {
console.log(response);
if (response.ok) {
return response.json();
} else {
let errors = new Error(response.statusText);
errors.response = response;
throw errors;
}
}
export function setMusic(music) {
return {
type: SET_MUSIC,
music
};
}
export function saveMusicFirestore(data) {
return dispatch => {
const db = firebase.firestore();
db.settings({
timestampsInSnapshots: true
});
const userRef = db.collection('collector').add({
data
});
return userRef;
};
}
export function saveMusic(data) {
return dispatch => {
return fetch('/api/music', {
method: 'post',
body: JSON.stringify(data),
headers: { 'Content-Type': 'application/json' }
});
};
}
export function fetchMusic() {
return dispatch => {
fetch('/api/music')
.then(res => res.json())
.then(data => dispatch(setMusic(data.music)));
};
}