Files
Mangarr/assets/vue/app/domain/manga/presentation/composables/useMangaChapters.js

24 lines
881 B
JavaScript

import { computed } from 'vue';
import { useQuery } from '@tanstack/vue-query';
import { ApiMangaRepository } from '../../infrastructure/api/apiMangaRepository';
export function useMangaChapters(mangaId) {
const mangaRepository = new ApiMangaRepository();
const query = useQuery({
queryKey: ['manga', mangaId, 'chapters'],
queryFn: async () => {
if (!mangaId.value) {
return Promise.resolve([]); // Retourne un tableau vide si pas d'ID
}
const response = await mangaRepository.getChapters(mangaId.value);
// Assure de toujours retourner un tableau
return Array.isArray(response) ? response : response?.items ?? [];
},
enabled: computed(() => !!mangaId.value)
});
// Retourne le résultat de useQuery (contenant data, isLoading, etc.)
return query;
}