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
|
|
|
|
2020-08-18 18:56:10 +00:00
|
|
|
// const API_BASE = 'https://us-central1-gamebrary-8c736.cloudfunctions.net';
|
|
|
|
const API_BASE = 'http://localhost:5001/gamebrary-8c736/us-central1';
|
2018-10-19 05:15:28 +00:00
|
|
|
|
|
|
|
export default {
|
2020-08-18 21:35:32 +00:00
|
|
|
//
|
|
|
|
// NEW STUFF
|
|
|
|
//
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
LOAD_IGDB_PLATFORMS() {
|
2020-08-18 18:56:10 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get(`${API_BASE}/platforms`)
|
|
|
|
.then(({ data }) => {
|
|
|
|
resolve(data);
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
LOAD_BOARDS({ state, commit }) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('boards').where('owner', '==', state.user.uid)
|
|
|
|
.get()
|
|
|
|
.then(({ docs }) => {
|
|
|
|
const boards = docs.length
|
|
|
|
? docs.map((doc) => {
|
|
|
|
const board = doc.data();
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: doc.id,
|
|
|
|
...board,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
: null;
|
|
|
|
|
|
|
|
if (boards) {
|
|
|
|
commit('SET_BOARDS', boards);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
LOAD_BOARD({ state }, id) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('boards')
|
|
|
|
.doc(id)
|
|
|
|
.get()
|
|
|
|
.then((docs) => {
|
|
|
|
const board = docs.data();
|
|
|
|
|
|
|
|
return state.user.uid === board.owner
|
|
|
|
? resolve(board)
|
|
|
|
: reject();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
CREATE_BOARD({ state, commit }, board) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
...board,
|
|
|
|
owner: state.user.uid,
|
|
|
|
};
|
|
|
|
|
|
|
|
db.collection('boards').add(payload)
|
|
|
|
.then(({ id }) => {
|
|
|
|
commit('ADD_BOARD', {
|
|
|
|
...payload,
|
|
|
|
id,
|
|
|
|
});
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
DELETE_BOARD({ commit }, id) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('boards').doc(id).delete()
|
|
|
|
.then(() => {
|
|
|
|
commit('REMOVE_BOARD', id);
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
//
|
|
|
|
// LEGACY
|
|
|
|
//
|
|
|
|
|
|
|
|
LOAD_GAMES_LEGACY({ commit }, gameList) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get(`${API_BASE}/games?games=${gameList}`)
|
|
|
|
.then(({ data }) => {
|
|
|
|
commit('CACHE_GAME_DATA', data);
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
SAVE_LIST_LEGACY({ commit, state }, payload) {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('lists').doc(state.user.uid).set(payload, { merge: true })
|
|
|
|
.then(() => {
|
|
|
|
commit('SAVE_LIST_LEGACYS', payload);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
SAVE_PROGRESSES_LEGACY({ state }) {
|
2019-12-18 05:47:35 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('progresses').doc(state.user.uid).set(state.progresses, { merge: true })
|
|
|
|
.then(() => resolve())
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_PROGRESSES_NO_MERGE_LEGACY({ state }) {
|
2019-12-18 05:47:35 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('progresses').doc(state.user.uid).set(state.progresses, { merge: false })
|
|
|
|
.then(() => resolve())
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_TAGS_LEGACY({ state }, tags) {
|
2019-12-03 18:26:19 +00:00
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
db.collection('tags').doc(state.user.uid).set(tags, { merge: true })
|
|
|
|
.then(() => resolve())
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_TAGS_NO_MERGE_LEGACY({ state }, tags) {
|
2019-12-03 18:26:19 +00:00
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
db.collection('tags').doc(state.user.uid).set(tags, { merge: false })
|
|
|
|
.then(() => resolve())
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_NOTES_LEGACY({ state }) {
|
2019-12-18 23:03:57 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('notes').doc(state.user.uid).set(state.notes, { merge: true })
|
|
|
|
.then(() => resolve())
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_NOTES_NO_MERGE_LEGACY({ state }) {
|
2019-12-18 23:03:57 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.collection('notes').doc(state.user.uid).set(state.notes, { merge: false })
|
|
|
|
.then(() => resolve())
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_LIST_NO_MERGE_LEGACY({ commit, state }, payload) {
|
2019-11-08 19:56:03 +00:00
|
|
|
const db = firebase.firestore();
|
2019-11-04 22:08:30 +00:00
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
db.collection('lists').doc(state.user.uid).set(payload, { merge: false })
|
|
|
|
.then(() => {
|
2020-08-18 21:35:32 +00:00
|
|
|
commit('SAVE_LIST_LEGACYS', payload);
|
2019-11-08 19:56:03 +00:00
|
|
|
});
|
|
|
|
},
|
2019-11-04 22:08:30 +00:00
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SAVE_SETTINGS_LEGACY({ commit, state }, settings) {
|
2019-11-08 19:56:03 +00:00
|
|
|
const db = firebase.firestore();
|
2019-10-18 18:15:09 +00:00
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
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-10-18 18:15:09 +00:00
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
SEARCH_LEGACY({ commit, state }, searchText) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get(`${API_BASE}/search?search=${searchText}&platform=${state.platform.id}`)
|
|
|
|
.then(({ data }) => {
|
|
|
|
commit('SET_SEARCH_RESULTS', data);
|
|
|
|
commit('CACHE_GAME_DATA', data);
|
|
|
|
resolve();
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// STUFF THAT REMAINS THE SAME
|
|
|
|
//
|
|
|
|
|
|
|
|
// TODO: use firebase email extension instead
|
|
|
|
SEND_WELCOME_EMAIL(context, additionalUserInfo) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (additionalUserInfo && additionalUserInfo.profile) {
|
|
|
|
axios.get(`${API_BASE}/email?address=${additionalUserInfo.profile.email}&template_id=welcome`)
|
|
|
|
.catch(reject);
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-15 00:02:34 +00:00
|
|
|
LOAD_RELEASES() {
|
2019-11-08 19:56:03 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get('https://api.github.com/repos/romancm/gamebrary/releases')
|
|
|
|
.then(({ data }) => {
|
2020-08-15 00:02:34 +00:00
|
|
|
resolve(data);
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-08-15 06:37:27 +00:00
|
|
|
LOAD_GITHUB_REPOSITORY() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get('https://api.github.com/repos/romancm/gamebrary')
|
|
|
|
.then(({ data }) => {
|
|
|
|
resolve(data);
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
LOAD_GITHUB_README() {
|
2020-08-15 00:02:34 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get('https://raw.githubusercontent.com/romancm/gamebrary/master/README.md')
|
|
|
|
.then(({ data }) => {
|
|
|
|
resolve(data);
|
2019-11-08 19:56:03 +00:00
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
2019-02-08 05:46:29 +00:00
|
|
|
|
2020-08-15 00:02:34 +00:00
|
|
|
LOAD_GAME(context, gameId) {
|
2019-11-08 19:56:03 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios.get(`${API_BASE}/game?gameId=${gameId}`)
|
|
|
|
.then(({ data }) => {
|
2020-08-15 00:02:34 +00:00
|
|
|
const [game] = data;
|
|
|
|
|
|
|
|
resolve(game);
|
2019-11-08 19:56:03 +00:00
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
};
|