|
@@ -8,6 +8,7 @@ const createStore = () => {
|
|
|
return new Vuex.Store({
|
|
|
state: {
|
|
|
headlines: [],
|
|
|
+ headline: null,
|
|
|
feed: [],
|
|
|
loading: false,
|
|
|
category: '',
|
|
@@ -19,6 +20,9 @@ const createStore = () => {
|
|
|
setHeadLines (state, headlines) {
|
|
|
state.headlines = headlines
|
|
|
},
|
|
|
+ setHeadline (state, headline) {
|
|
|
+ state.headline = headline
|
|
|
+ },
|
|
|
setLoading (state, loading) {
|
|
|
state.loading = loading
|
|
|
},
|
|
@@ -89,6 +93,31 @@ const createStore = () => {
|
|
|
// console.log(error)
|
|
|
}
|
|
|
},
|
|
|
+ async loadHeadline ({ commit }, headlineSlug) {
|
|
|
+ const headlineRef = db.collection('headlines').doc(headlineSlug)
|
|
|
+
|
|
|
+ await headlineRef.get().then((doc) => {
|
|
|
+ if (doc.exists) {
|
|
|
+ const headline = doc.data()
|
|
|
+ this.commit('setHeadline', headline)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async saveHeadline (context, headline) {
|
|
|
+ const headlineRef = db.collection('headlines').doc(headline.slug)
|
|
|
+
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ let headlineId
|
|
|
+ await headlineRef.get().then((doc) => {
|
|
|
+ if (doc.exists) {
|
|
|
+ headlineId = doc.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (!headlineId) {
|
|
|
+ await headlineRef.set(headline)
|
|
|
+ }
|
|
|
+ },
|
|
|
async removeHeadlineFromFeed ({ state }, headline) {
|
|
|
const headlineRef = db.collection(`users/${state.user.email}/feed`).doc(headline.title)
|
|
|
await headlineRef.delete()
|
|
@@ -128,6 +157,7 @@ const createStore = () => {
|
|
|
},
|
|
|
getters: {
|
|
|
headlines: state => state.headlines,
|
|
|
+ headline: state => state.headline,
|
|
|
feed: state => state.feed,
|
|
|
loading: state => state.loading,
|
|
|
category: state => state.category,
|