generated from Flycro/laravel-nuxt
93 lines
2.2 KiB
TypeScript
93 lines
2.2 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
export enum BookRecommendationStatusEnum {
|
|
PENDING = 'PENDING',
|
|
REJECTED = 'REJECTED',
|
|
ACTIVE = 'ACTIVE',
|
|
COMPLETED = 'COMPLETED',
|
|
}
|
|
|
|
export interface BookRecommendation {
|
|
id: number
|
|
book_name: string
|
|
author: string
|
|
description: string
|
|
isbn: string
|
|
pages: number
|
|
recommended_by?: number
|
|
recommender?: {
|
|
ulid: number
|
|
name: string
|
|
email: string
|
|
avatar: string
|
|
}
|
|
status: BookRecommendationStatusEnum
|
|
cover_image?: string
|
|
published_at?: string
|
|
}
|
|
|
|
export const useBookRecommendationStore = defineStore('bookRecommendations', () => {
|
|
const recommendations = ref<BookRecommendation[]>([])
|
|
|
|
const statusOptions = [
|
|
{
|
|
name: 'Ausstehend',
|
|
value: BookRecommendationStatusEnum.PENDING,
|
|
color: 'orange',
|
|
},
|
|
{
|
|
name: 'Abgelehnt',
|
|
value: BookRecommendationStatusEnum.REJECTED,
|
|
color: 'red',
|
|
},
|
|
{
|
|
name: 'Aktiv',
|
|
value: BookRecommendationStatusEnum.ACTIVE,
|
|
color: 'green',
|
|
},
|
|
{
|
|
name: 'Abgeschlossen',
|
|
value: BookRecommendationStatusEnum.COMPLETED,
|
|
color: 'primary',
|
|
|
|
},
|
|
]
|
|
|
|
// Fetch all book recommendations
|
|
const { refresh: fetchRecommendations, status: fetchRecommendationsStatus } = useFetch<BookRecommendation[]>('book-recommendations?with=recommender,votes', {
|
|
immediate: false,
|
|
onResponse({ response }) {
|
|
if (response.status === 200) {
|
|
recommendations.value = response._data
|
|
}
|
|
},
|
|
})
|
|
|
|
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
|
|
}
|
|
},
|
|
})
|
|
|
|
function resetRecommendations() {
|
|
recommendations.value = []
|
|
}
|
|
|
|
return {
|
|
recommendations,
|
|
resetRecommendations,
|
|
statusOptions,
|
|
fetchRecommendations,
|
|
fetchRecommendationsStatus,
|
|
fetchActiveRecommendations,
|
|
fetchActiveRecommendationsStatus,
|
|
}
|
|
})
|
|
|
|
if (import.meta.hot) {
|
|
import.meta.hot.accept(acceptHMRUpdate(useBookRecommendationStore, import.meta.hot))
|
|
}
|