diff options
author | Cyrille Bollu <cyrpub@bollu.be> | 2019-07-10 17:39:49 +0200 |
---|---|---|
committer | Cyrille Bollu <cyrpub@bollu.be> | 2019-07-10 17:39:49 +0200 |
commit | 27afa184362a6ae72c2e77985a258c9298ee9d2a (patch) | |
tree | 7acafb112a5235ef8d643b1da9b9d46de8ff5b5e /src/store | |
parent | 2823dc66eb2545efc6793120377c7a934b0352b8 (diff) |
Creates a 'like' button.
The following problems remain:
1- Once a post has been liked (the star icon turned yellow), it is impossible
to unlike it (the star stays yellow, no matter what)
2- Communication with backend doesn't work; 'got 'failed to like post'
Signed-off-by: Cyrille Bollu <cyrpub@bollu.be>
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/timeline.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/store/timeline.js b/src/store/timeline.js index accf5a7b..50dac734 100644 --- a/src/store/timeline.js +++ b/src/store/timeline.js @@ -54,6 +54,22 @@ const mutations = { setAccount(state, account) { state.account = account }, + likePost(state, { post, parentAnnounce }) { + if (typeof state.timeline[post.id] !== 'undefined') { + Vue.set(state.timeline[post.id].action.values, 'liked', true) + } + if (typeof parentAnnounce.id !== 'undefined') { + Vue.set(state.timeline[parentAnnounce.id].cache[parentAnnounce.object].object.action.values, 'liked', true) + } + }, + unlikePost(state, { post, parentAnnounce }) { + if (typeof state.timeline[post.id] !== 'undefined') { + Vue.set(state.timeline[post.id].action.values, 'liked', false) + } + if (typeof parentAnnounce.id !== 'undefined') { + Vue.set(state.timeline[parentAnnounce.id].cache[parentAnnounce.object].object.action.values, 'liked', false) + } + }, boostPost(state, { post, parentAnnounce }) { if (typeof state.timeline[post.id] !== 'undefined') { Vue.set(state.timeline[post.id].action.values, 'boosted', true) @@ -113,6 +129,30 @@ const actions = { console.error('Failed to delete the post', error) }) }, + postLike(context, { post, parentAnnounce }) { + return new Promise((resolve, reject) => { + axios.post(OC.generateUrl(`apps/social/api/v1/post/like?postId=${post.id}`)).then((response) => { + context.commit('likePost', { post, parentAnnounce }) + // eslint-disable-next-line no-console + console.log('Post liked with token ' + response.data.result.token) + resolve(response) + }).catch((error) => { + OC.Notification.showTemporary('Failed to like post') + console.error('Failed to like post', error.response) + reject(error) + }) + }) + }, + postUnlike(context, { post, parentAnnounce }) { + return axios.delete(OC.generateUrl(`apps/social/api/v1/post/like?postId=${post.id}`)).then((response) => { + context.commit('unlikePost', { post, parentAnnounce }) + // eslint-disable-next-line no-console + console.log('Boost unliked with token ' + response.data.result.token) + }).catch((error) => { + OC.Notification.showTemporary('Failed to unlike post') + console.error('Failed to unlike post', error) + }) + }, postBoost(context, { post, parentAnnounce }) { return new Promise((resolve, reject) => { axios.post(OC.generateUrl(`apps/social/api/v1/post/boost?postId=${post.id}`)).then((response) => { |