Add Micropub Like

This commit is contained in:
Peter Stuifzand 2018-08-29 18:11:19 +02:00
parent aaa8f82c7b
commit fc7fddc574
4 changed files with 31 additions and 4 deletions

View File

@ -2,6 +2,9 @@ Some features that need to be implemented
- Get Microsub endpoint from homepage of user
- Micropub
- Like
- Reply
- Repost
- Infinite scrolling
- Scrolling backward and forward
- Preview

View File

@ -10,7 +10,7 @@
<div class="media">
<div class="media-left">
<figure class="image is-48x48">
<img :src="item.author.photo"/>
<img :src="author_photo"/>
</figure>
</div>
@ -52,7 +52,7 @@
this.$emit('debug', this.item)
},
like() {
this.$emit('like', this.item)
this.$store.dispatch('micropubLike', this.item)
},
repost() {
this.$emit('repost', this.item)
@ -96,13 +96,25 @@
return []
},
author_name() {
if (!this.item.author) {
return 'anonymouse';
}
if (!this.item.author.name) {
return new URL(this.item.author.url).hostname
}
return this.item.author.name
},
author_url() {
if (!this.item.author) {
return '';
}
return this.item.author.url
},
author_photo() {
if (!this.item.author) {
return '';
}
return this.item.author.photo
}
}
}

View File

@ -63,6 +63,7 @@
})
micropub.getAuthUrl().then(url => {
let options = {
micropubEndpoint: micropub.options.micropubEndpoint,
tokenEndpoint: micropub.options.tokenEndpoint,
loginState: state
}

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import Vuex from 'vuex'
import Micropub from 'micropub-helper';
const baseurl = "https://microsub.stuifzandapp.com/microsub"
@ -18,12 +19,12 @@ export default new Vuex.Store({
};
let loginData = JSON.parse(window.localStorage.getItem('login_data'))
if (loginData) {
newState = { ...newState, ...loginData }
newState = {...newState, ...loginData}
newState.logged_in = loginData.access_token && loginData.access_token.length > 0
}
let endpoints = JSON.parse(window.localStorage.getItem('endpoints'))
if (endpoints) {
newState = { ...newState, ...endpoints}
newState = {...newState, ...endpoints}
}
return newState
},
@ -105,6 +106,16 @@ export default new Vuex.Store({
'Authorization': 'Bearer ' + this.state.access_token
}
})
},
micropubLike(_, item) {
// eslint-disable-next-line
let micropub = new Micropub({
token: this.state.access_token,
micropubEndpoint: this.state.micropubEndpoint
})
micropub.postMicropub({
'like-of': [item.url]
})
}
}
})