feat: Realtime for Votes + Deadlines

This commit is contained in:
2024-03-24 01:36:16 +01:00
parent b1cb25c823
commit 5c0dab3448
9 changed files with 133 additions and 1 deletions

View File

@@ -123,6 +123,17 @@ export const useBookRecommendationStore = defineStore('bookRecommendations', ()
})
}
const createVoteWS = async (data: Partial<Vote>) => {
const index = recommendations.value.findIndex(r => r.id === data.book_recommendation_id)
// check if vote already exists otherwise add an empty array
if (index !== -1) {
if (!recommendations.value[index]?.votes) {
recommendations.value[index].votes = []
}
recommendations.value[index].votes.push(data)
}
}
function resetRecommendations() {
recommendations.value = []
}
@@ -133,6 +144,7 @@ export const useBookRecommendationStore = defineStore('bookRecommendations', ()
updateRecommendationWS,
deleteRecommendationWS,
createRecommendationWS,
createVoteWS,
statusOptions,
fetchRecommendations,
fetchRecommendationsStatus,