forked from AkkomaGang/akkoma-fe
Add unfollowing.
This commit is contained in:
parent
2088b3c4dd
commit
8f494b14f0
3 changed files with 23 additions and 1 deletions
|
@ -13,6 +13,9 @@
|
||||||
<div class="followed">
|
<div class="followed">
|
||||||
<span v-if="user.following">
|
<span v-if="user.following">
|
||||||
Following them!
|
Following them!
|
||||||
|
<button @click="unfollowUser">
|
||||||
|
Unfollow!
|
||||||
|
</button>
|
||||||
</span>
|
</span>
|
||||||
<span v-if="!user.following" >
|
<span v-if="!user.following" >
|
||||||
<button @click="followUser">
|
<button @click="followUser">
|
||||||
|
@ -62,6 +65,11 @@
|
||||||
const store = this.$store
|
const store = this.$store
|
||||||
store.state.api.backendInteractor.followUser(this.user.id)
|
store.state.api.backendInteractor.followUser(this.user.id)
|
||||||
.then((followedUser) => store.commit('addNewUsers', [followedUser]))
|
.then((followedUser) => store.commit('addNewUsers', [followedUser]))
|
||||||
|
},
|
||||||
|
unfollowUser () {
|
||||||
|
const store = this.$store
|
||||||
|
store.state.api.backendInteractor.unfollowUser(this.user.id)
|
||||||
|
.then((unfollowedUser) => store.commit('addNewUsers', [unfollowedUser]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ const CONVERSATION_URL = '/api/statusnet/conversation'
|
||||||
const MENTIONS_URL = '/api/statuses/mentions.json'
|
const MENTIONS_URL = '/api/statuses/mentions.json'
|
||||||
const FRIENDS_URL = '/api/statuses/friends.json'
|
const FRIENDS_URL = '/api/statuses/friends.json'
|
||||||
const FOLLOWING_URL = '/api/friendships/create.json'
|
const FOLLOWING_URL = '/api/friendships/create.json'
|
||||||
// const UNFOLLOWING_URL = '/api/friendships/create.json'
|
const UNFOLLOWING_URL = '/api/friendships/destroy.json'
|
||||||
// const USER_URL = '/api/users/show.json'
|
// const USER_URL = '/api/users/show.json'
|
||||||
|
|
||||||
const oldfetch = window.fetch
|
const oldfetch = window.fetch
|
||||||
|
@ -41,6 +41,14 @@ const followUser = ({id, credentials}) => {
|
||||||
}).then((data) => data.json())
|
}).then((data) => data.json())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unfollowUser = ({id, credentials}) => {
|
||||||
|
let url = `${UNFOLLOWING_URL}?user_id=${id}`
|
||||||
|
return fetch(url, {
|
||||||
|
headers: authHeaders(credentials),
|
||||||
|
method: 'POST'
|
||||||
|
}).then((data) => data.json())
|
||||||
|
}
|
||||||
|
|
||||||
const fetchFriends = ({credentials}) => {
|
const fetchFriends = ({credentials}) => {
|
||||||
return fetch(FRIENDS_URL, { headers: authHeaders(credentials) })
|
return fetch(FRIENDS_URL, { headers: authHeaders(credentials) })
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
|
@ -155,6 +163,7 @@ const apiService = {
|
||||||
fetchMentions,
|
fetchMentions,
|
||||||
fetchFriends,
|
fetchFriends,
|
||||||
followUser,
|
followUser,
|
||||||
|
unfollowUser,
|
||||||
favorite,
|
favorite,
|
||||||
unfavorite,
|
unfavorite,
|
||||||
retweet,
|
retweet,
|
||||||
|
|
|
@ -21,12 +21,17 @@ const backendInteractorService = (credentials) => {
|
||||||
return apiService.followUser({credentials, id})
|
return apiService.followUser({credentials, id})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unfollowUser = (id) => {
|
||||||
|
return apiService.unfollowUser({credentials, id})
|
||||||
|
}
|
||||||
|
|
||||||
const backendInteractorServiceInstance = {
|
const backendInteractorServiceInstance = {
|
||||||
fetchStatus,
|
fetchStatus,
|
||||||
fetchConversation,
|
fetchConversation,
|
||||||
fetchMentions,
|
fetchMentions,
|
||||||
fetchFriends,
|
fetchFriends,
|
||||||
followUser,
|
followUser,
|
||||||
|
unfollowUser,
|
||||||
verifyCredentials: apiService.verifyCredentials
|
verifyCredentials: apiService.verifyCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue