- Correction du dropdown toolbar : prop align (left/right) pour éviter le débordement hors écran côté droit - Filtre de collection par statut (all/completed/ongoing) persisté dans userPreferencesStore - toolbarConfig rendu réactif (computed) avec isSelected sur Filter, Sort et View - Modale Options d'affichage par vue (Grille, Overview, Table) avec toggles persistés - Composant ToggleRow réutilisable - Normalisation author → authors dans l'entité Manga (l'API renvoie author string)
154 lines
6.4 KiB
Vue
154 lines
6.4 KiB
Vue
<template>
|
|
<div class="flex flex-col h-full">
|
|
<Toolbar :config="toolbarConfig" />
|
|
<div class="overflow-y-auto flex-1">
|
|
<div class="w-full">
|
|
<MangaGrid v-if="viewMode === 'grid'" :mangas="pagedItems" :options="prefs.displayOptions.grid" />
|
|
<MangaOverview
|
|
v-else-if="viewMode === 'list'"
|
|
:mangas="pagedItems"
|
|
:options="prefs.displayOptions.overview"
|
|
@manga-click="handleMangaClick" />
|
|
<MangaTable v-else-if="viewMode === 'table'" :mangas="pagedItems" :options="prefs.displayOptions.table" />
|
|
<Pagination
|
|
v-if="totalPages > 1"
|
|
:current-page="currentPage"
|
|
:total-pages="totalPages"
|
|
:total="sortedCollection.length"
|
|
:limit="prefs.itemsPerPage"
|
|
:has-next-page="currentPage < totalPages"
|
|
:has-previous-page="currentPage > 1"
|
|
@page-change="currentPage = $event" />
|
|
<div
|
|
v-if="isBackgroundLoading"
|
|
class="fixed bottom-4 right-4 bg-gray-800 text-white px-4 py-2 rounded-lg shadow-lg">
|
|
Mise à jour en cours...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<HomeDisplaySettingsModal
|
|
:is-open="isDisplaySettingsOpen"
|
|
:options="prefs.displayOptions"
|
|
@close="isDisplaySettingsOpen = false"
|
|
@update="({ view, key, value }) => prefs.setDisplayOption(view, key, value)" />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import {
|
|
ArrowPathIcon,
|
|
ArrowsUpDownIcon,
|
|
Cog6ToothIcon,
|
|
EyeIcon,
|
|
FunnelIcon,
|
|
MagnifyingGlassIcon
|
|
} from '@heroicons/vue/24/outline';
|
|
import { storeToRefs } from 'pinia';
|
|
import { computed, onMounted, ref, watch } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { useUserPreferencesStore } from '../../../../domain/setting/application/store/userPreferencesStore';
|
|
import Pagination from '../../../../shared/components/ui/Pagination.vue';
|
|
import Toolbar from '../../../../shared/components/ui/Toolbar.vue';
|
|
import { useMangaStore } from '../../application/store/mangaStore';
|
|
import HomeDisplaySettingsModal from '../components/HomeDisplaySettingsModal.vue';
|
|
import MangaGrid from '../components/MangaGrid.vue';
|
|
import MangaOverview from '../components/MangaOverview.vue';
|
|
import MangaTable from '../components/MangaTable.vue';
|
|
|
|
const router = useRouter();
|
|
const mangaStore = useMangaStore();
|
|
const prefs = useUserPreferencesStore();
|
|
|
|
const {
|
|
collection,
|
|
loadingCollection: loading,
|
|
errorCollection: error,
|
|
isBackgroundLoadingCollection: isBackgroundLoading
|
|
} = storeToRefs(mangaStore);
|
|
|
|
const viewMode = ref(prefs.defaultView);
|
|
const currentPage = ref(1);
|
|
const isDisplaySettingsOpen = ref(false);
|
|
|
|
onMounted(() => {
|
|
mangaStore.loadCollection();
|
|
});
|
|
|
|
const handleMangaClick = manga => {
|
|
router.push({ name: 'manga-details', params: { id: manga.id } });
|
|
};
|
|
|
|
const sortedCollection = computed(() => {
|
|
let items = [...(collection.value?.items || [])];
|
|
if (prefs.filterBy === 'completed') {
|
|
items = items.filter(m => m.status?.toLowerCase() === 'completed');
|
|
} else if (prefs.filterBy === 'ongoing') {
|
|
items = items.filter(m => m.status?.toLowerCase() === 'ongoing');
|
|
}
|
|
if (prefs.sortBy === 'title') {
|
|
items.sort((a, b) => a.title.localeCompare(b.title));
|
|
} else if (prefs.sortBy === 'addedAt') {
|
|
items.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
|
|
}
|
|
return items;
|
|
});
|
|
|
|
const pagedItems = computed(() => {
|
|
const start = (currentPage.value - 1) * prefs.itemsPerPage;
|
|
return sortedCollection.value.slice(start, start + prefs.itemsPerPage);
|
|
});
|
|
|
|
const totalPages = computed(() => Math.ceil(sortedCollection.value.length / prefs.itemsPerPage));
|
|
|
|
watch(() => prefs.itemsPerPage, () => {
|
|
currentPage.value = 1;
|
|
});
|
|
|
|
const toolbarConfig = computed(() => ({
|
|
leftSection: [
|
|
{
|
|
icon: ArrowPathIcon,
|
|
label: 'Refresh',
|
|
type: 'button',
|
|
onClick: () => mangaStore.refreshCollectionInBackground(),
|
|
active: isBackgroundLoading.value
|
|
},
|
|
{ icon: MagnifyingGlassIcon, label: 'Search', type: 'button', onClick: () => {} }
|
|
],
|
|
rightSection: [
|
|
{ icon: Cog6ToothIcon, label: 'Options', type: 'button', onClick: () => { isDisplaySettingsOpen.value = true; } },
|
|
{
|
|
icon: EyeIcon,
|
|
type: 'dropdown',
|
|
label: 'View',
|
|
items: [
|
|
{ label: 'Overview', isSelected: prefs.defaultView === 'list', onClick: () => { viewMode.value = 'list'; prefs.setDefaultView('list'); } },
|
|
{ label: 'Grid', isSelected: prefs.defaultView === 'grid', onClick: () => { viewMode.value = 'grid'; prefs.setDefaultView('grid'); } },
|
|
{ label: 'Table', isSelected: prefs.defaultView === 'table', onClick: () => { viewMode.value = 'table'; prefs.setDefaultView('table'); } }
|
|
]
|
|
},
|
|
{
|
|
icon: ArrowsUpDownIcon,
|
|
type: 'dropdown',
|
|
label: 'Sort',
|
|
items: [
|
|
{ label: 'Title', isSelected: prefs.sortBy === 'title', onClick: () => prefs.setSortBy('title') },
|
|
{ label: "Date d'ajout", isSelected: prefs.sortBy === 'addedAt', onClick: () => prefs.setSortBy('addedAt') },
|
|
{ label: 'Progression', isSelected: prefs.sortBy === 'progress', onClick: () => prefs.setSortBy('progress') }
|
|
]
|
|
},
|
|
{
|
|
icon: FunnelIcon,
|
|
type: 'dropdown',
|
|
label: 'Filter',
|
|
items: [
|
|
{ label: 'All', isSelected: prefs.filterBy === 'all', onClick: () => prefs.setFilterBy('all') },
|
|
{ label: 'Completed', isSelected: prefs.filterBy === 'completed', onClick: () => prefs.setFilterBy('completed') },
|
|
{ label: 'In Progress', isSelected: prefs.filterBy === 'ongoing', onClick: () => prefs.setFilterBy('ongoing') }
|
|
]
|
|
}
|
|
]
|
|
}));
|
|
</script>
|