2018-10-19 05:15:28 +00:00
|
|
|
import axios from 'axios';
|
2019-10-01 22:27:34 +00:00
|
|
|
import firebase from 'firebase/app';
|
|
|
|
import 'firebase/firestore';
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2019-11-04 18:25:17 +00:00
|
|
|
const API_BASE = 'https://us-central1-gamebrary-8c736.cloudfunctions.net';
|
|
|
|
// const API_BASE = 'http://localhost:5000/gamebrary-8c736/us-central1';
|
2018-10-19 05:15:28 +00:00
|
|
|
|
|
|
|
export default {
|
2018-10-19 06:04:27 +00:00
|
|
|
LOAD_GAMES({ commit }, gameList) {
|
2018-10-19 05:15:28 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2019-11-04 18:25:17 +00:00
|
|
|
axios.get(`${API_BASE}/games?games=${gameList}`)
|
2018-10-19 05:15:28 +00:00
|
|
|
.then(({ data }) => {
|
|
|
|
commit('CACHE_GAME_DATA', data);
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-10-01 22:27:34 +00:00
|
|
|
SAVE_LIST({ commit, state }, payload) {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('lists').doc(state.user.uid).set(payload, { merge: true })
|
|
|
|
.then(() => {
|
|
|
|
commit('SAVE_LISTS', payload);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-10-18 18:15:09 +00:00
|
|
|
SAVE_SETTINGS({ commit, state }, settings) {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
db.collection('settings').doc(state.user.uid).set(settings, { merge: true })
|
|
|
|
.then(() => {
|
|
|
|
commit('SET_SETTINGS', settings);
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-02-08 05:46:29 +00:00
|
|
|
LOAD_RELEASES({ commit }) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2019-05-21 22:33:42 +00:00
|
|
|
axios.get('https://api.github.com/repos/romancm/gamebrary/releases')
|
2019-02-08 05:46:29 +00:00
|
|
|
.then(({ data }) => {
|
|
|
|
commit('SET_RELEASES', data);
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-11-21 02:43:10 +00:00
|
|
|
LOAD_PUBLIC_GAMES({ commit }, gameList) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2019-11-04 18:25:17 +00:00
|
|
|
axios.get(`${API_BASE}/games?games=${gameList}`)
|
2018-11-21 02:43:10 +00:00
|
|
|
.then(({ data }) => {
|
|
|
|
commit('SET_PUBLIC_GAME_DATA', data);
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-11-17 22:21:29 +00:00
|
|
|
LOAD_GAME({ commit }, gameId) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2019-11-04 18:25:17 +00:00
|
|
|
axios.get(`${API_BASE}/game?gameId=${gameId}`)
|
2018-11-17 22:21:29 +00:00
|
|
|
.then(({ data }) => {
|
|
|
|
commit('SET_ACTIVE_GAME', data);
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-25 06:33:15 +00:00
|
|
|
SEARCH({ commit, state }, searchText) {
|
2018-10-19 05:15:28 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2019-11-04 18:25:17 +00:00
|
|
|
axios.get(`${API_BASE}/search?search=${searchText}&platform=${state.platform.id}`)
|
2018-10-19 05:15:28 +00:00
|
|
|
.then(({ data }) => {
|
2019-06-09 02:04:07 +00:00
|
|
|
commit('SET_SEARCH_RESULTS', data);
|
|
|
|
commit('CACHE_GAME_DATA', data);
|
|
|
|
resolve();
|
2018-10-19 05:15:28 +00:00
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
2018-11-27 06:46:01 +00:00
|
|
|
|
2019-04-03 00:14:32 +00:00
|
|
|
SEND_WELCOME_EMAIL(context, additionalUserInfo) {
|
2019-04-02 23:45:01 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2019-04-03 00:14:32 +00:00
|
|
|
if (additionalUserInfo && additionalUserInfo.profile) {
|
2019-11-04 18:25:17 +00:00
|
|
|
axios.get(`${API_BASE}/email?address=${additionalUserInfo.profile.email}&template_id=welcome`)
|
2019-04-03 00:14:32 +00:00
|
|
|
.catch(reject);
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
2019-04-02 23:45:01 +00:00
|
|
|
});
|
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
};
|