feat: debut d'un front vue.js + ajout de cursorrules
This commit is contained in:
parent
ca9a74fe69
commit
bee8572dc5
72
assets/vue/app/domain/manga/application/store/mangaStore.js
Normal file
72
assets/vue/app/domain/manga/application/store/mangaStore.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { ApiMangaRepository } from '../../infrastructure/api/apiMangaRepository';
|
||||
|
||||
const mangaRepository = new ApiMangaRepository();
|
||||
|
||||
export const useMangaStore = defineStore('manga', () => {
|
||||
const collection = ref(null);
|
||||
const detailedMangas = ref({});
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
const isBackgroundLoading = ref(false);
|
||||
|
||||
const loadCollection = async () => {
|
||||
if (loading.value) return;
|
||||
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
collection.value = await mangaRepository.getCollection();
|
||||
} catch (err) {
|
||||
error.value = err.message;
|
||||
console.error('Failed to load collection:', err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const refreshCollectionInBackground = async () => {
|
||||
if (isBackgroundLoading.value) return;
|
||||
|
||||
isBackgroundLoading.value = true;
|
||||
|
||||
try {
|
||||
const updatedCollection = await mangaRepository.getCollection();
|
||||
collection.value = updatedCollection;
|
||||
} catch (err) {
|
||||
console.error('Failed to refresh collection:', err);
|
||||
} finally {
|
||||
isBackgroundLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const loadMangaDetail = async (slug) => {
|
||||
if (detailedMangas.value[slug]) return;
|
||||
|
||||
try {
|
||||
const manga = await mangaRepository.getMangaBySlug(slug);
|
||||
detailedMangas.value[slug] = manga;
|
||||
} catch (err) {
|
||||
console.error(`Failed to load manga details for ${slug}:`, err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
const getMangaFromCollection = (slug) => {
|
||||
return collection.value?.items.find(manga => manga.slug === slug);
|
||||
};
|
||||
|
||||
return {
|
||||
collection,
|
||||
detailedMangas,
|
||||
loading,
|
||||
error,
|
||||
isBackgroundLoading,
|
||||
loadCollection,
|
||||
refreshCollectionInBackground,
|
||||
loadMangaDetail,
|
||||
getMangaFromCollection
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user