generated from Flycro/laravel-nuxt
feat: BR Overview + Modal for New Recommendations
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
enum BookRecommendationStatusEnum {
|
||||
export enum BookRecommendationStatusEnum {
|
||||
PENDING = 'PENDING',
|
||||
REJECTED = 'REJECTED',
|
||||
ACTIVE = 'ACTIVE',
|
||||
@@ -23,6 +23,7 @@ export interface BookRecommendation {
|
||||
}
|
||||
status: BookRecommendationStatusEnum
|
||||
cover_image?: string
|
||||
published_at?: string
|
||||
}
|
||||
|
||||
export const useBookRecommendationStore = defineStore('bookRecommendations', () => {
|
||||
@@ -30,20 +31,25 @@ export const useBookRecommendationStore = defineStore('bookRecommendations', ()
|
||||
|
||||
const statusOptions = [
|
||||
{
|
||||
name: 'Pending',
|
||||
name: 'Ausstehend',
|
||||
value: BookRecommendationStatusEnum.PENDING,
|
||||
color: 'orange',
|
||||
},
|
||||
{
|
||||
name: 'Rejected',
|
||||
name: 'Abgelehnt',
|
||||
value: BookRecommendationStatusEnum.REJECTED,
|
||||
color: 'red',
|
||||
},
|
||||
{
|
||||
name: 'Active',
|
||||
name: 'Aktiv',
|
||||
value: BookRecommendationStatusEnum.ACTIVE,
|
||||
color: 'green',
|
||||
},
|
||||
{
|
||||
name: 'Completed',
|
||||
name: 'Abgeschlossen',
|
||||
value: BookRecommendationStatusEnum.COMPLETED,
|
||||
color: 'primary',
|
||||
|
||||
},
|
||||
]
|
||||
|
||||
@@ -57,29 +63,30 @@ export const useBookRecommendationStore = defineStore('bookRecommendations', ()
|
||||
},
|
||||
})
|
||||
|
||||
const deleteRecommendation = async (id: number) => {
|
||||
try {
|
||||
const { error } = await useFetch(`book-recommendations/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
const { refresh: fetchActiveRecommendations, status: fetchActiveRecommendationsStatus } = useFetch<BookRecommendation[]>('book-recommendations?with=recommender,votes&status=ACTIVE', {
|
||||
immediate: false,
|
||||
onResponse({ response }) {
|
||||
if (response.status === 200) {
|
||||
recommendations.value = response._data
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
if (error.value) {
|
||||
console.error('Failed to delete book recommendation:', error.value)
|
||||
}
|
||||
else {
|
||||
recommendations.value = recommendations.value.filter(rec => rec.id !== id)
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('An error occurred while deleting a book recommendation:', e)
|
||||
}
|
||||
function resetRecommendations() {
|
||||
recommendations.value = []
|
||||
}
|
||||
|
||||
return {
|
||||
recommendations,
|
||||
resetRecommendations,
|
||||
statusOptions,
|
||||
fetchRecommendations,
|
||||
fetchRecommendationsStatus,
|
||||
deleteRecommendation,
|
||||
fetchActiveRecommendations,
|
||||
fetchActiveRecommendationsStatus,
|
||||
}
|
||||
})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useBookRecommendationStore, import.meta.hot))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user