gamebrary/src/store/actions.js

27 lines
898 B
JavaScript
Raw Normal View History

2018-10-19 05:15:28 +00:00
import axios from 'axios';
2018-10-19 06:04:27 +00:00
const FIREBASE_URL = 'https://us-central1-gamebrary-8c736.cloudfunctions.net';
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) => {
2018-10-19 06:04:27 +00:00
axios.get(`${FIREBASE_URL}/games?games=${gameList.join(',')}`)
2018-10-19 05:15:28 +00:00
.then(({ data }) => {
commit('CACHE_GAME_DATA', data);
resolve();
}).catch(reject);
});
},
SEARCH({ commit, state }, searchText) {
2018-10-19 05:15:28 +00:00
return new Promise((resolve, reject) => {
axios.get(`${FIREBASE_URL}/search?searchText=${searchText}&platformId=${state.platform.id}`)
2018-10-19 05:15:28 +00:00
.then(({ data }) => {
commit('SET_SEARCH_RESULTS', data);
commit('CACHE_GAME_DATA', data);
resolve();
}).catch(reject);
});
},
};