Ocelot-Social/webapp/store/pinnedPosts.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

44 lines
1005 B
JavaScript

import { postsPinnedCountsQuery } from '~/graphql/PostQuery'
export const state = () => {
return {
maxPinnedPosts: 0,
currentlyPinnedPosts: 0,
}
}
export const mutations = {
pinPost(state) {
state.currentlyPinnedPosts++
},
unpinPost(state) {
state.currentlyPinnedPosts--
},
setMaxPinnedPosts(state, value) {
state.maxPinnedPosts = value
},
setCurrentlyPinnedPosts(state, value) {
state.currentlyPinnedPosts = value
},
}
export const getters = {
maxPinnedPosts(state) {
return state.maxPinnedPosts
},
currentlyPinnedPosts(state) {
return state.currentlyPinnedPosts
},
}
export const actions = {
async fetch({ commit }) {
const client = this.app.apolloProvider.defaultClient
const {
data: { PostsPinnedCounts },
} = await client.query({ query: postsPinnedCountsQuery() })
commit('setMaxPinnedPosts', PostsPinnedCounts.maxPinnedPosts)
commit('setCurrentlyPinnedPosts', PostsPinnedCounts.currentlyPinnedPosts)
},
}