Ocelot-Social/webapp/mixins/postListActions.js
Moriz Wahl b736a2a2e3
feat(backend): pin more than one post (#8598)
* feat(backend): pin more than one post

* add postPinnedCount query, better names for env variable

* add store and mixin for pinned posts counts

* test pinned post store

* context menu for pin posts

* fix typos

* unpin posts is always possible

---------

Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
2025-05-28 19:12:27 +02:00

65 lines
1.8 KiB
JavaScript

import PostMutations from '~/graphql/PostMutations'
import { mapMutations } from 'vuex'
export default {
methods: {
removePostFromList(deletedPost, posts) {
return posts.filter((post) => {
return post.id !== deletedPost.id
})
},
pinPost(post, refetchPostList = () => {}) {
this.$apollo
.mutate({
mutation: PostMutations().pinPost,
variables: {
id: post.id,
},
})
.then(() => {
this.$toast.success(this.$t('post.menu.pinnedSuccessfully'))
this.storePinPost()
refetchPostList()
})
.catch((error) => this.$toast.error(error.message))
},
unpinPost(post, refetchPostList = () => {}) {
this.$apollo
.mutate({
mutation: PostMutations().unpinPost,
variables: {
id: post.id,
},
})
.then(() => {
this.$toast.success(this.$t('post.menu.unpinnedSuccessfully'))
this.storeUnpinPost()
refetchPostList()
})
.catch((error) => this.$toast.error(error.message))
},
toggleObservePost(postId, value, refetchPostList = () => {}) {
this.$apollo
.mutate({
mutation: PostMutations().toggleObservePost,
variables: {
value,
id: postId,
},
})
.then(() => {
const message = this.$t(
`post.menu.${value ? 'observedSuccessfully' : 'unobservedSuccessfully'}`,
)
this.$toast.success(message)
refetchPostList()
})
.catch((error) => this.$toast.error(error.message))
},
...mapMutations({
storePinPost: 'pinnedPosts/pinPost',
storeUnpinPost: 'pinnedPosts/unpinPost',
}),
},
}