feat: front update

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-22 15:38:05 +01:00
parent 7303d63198
commit 4f4f86fb91
5 changed files with 44 additions and 34 deletions

View File

@@ -47,7 +47,11 @@ function mangaReducer(state, action) {
...state.collection,
items: state.collection.items.map(manga =>
manga.slug === action.payload.slug
? { ...manga, ...action.payload }
? {
...manga,
...action.payload,
createdAt: manga.createdAt || action.payload.createdAt
}
: manga
)
} : state.collection;
@@ -57,7 +61,10 @@ function mangaReducer(state, action) {
collection: updatedCollection,
detailedMangas: {
...state.detailedMangas,
[action.payload.slug]: action.payload
[action.payload.slug]: {
...action.payload,
createdAt: state.collection?.items.find(m => m.slug === action.payload.slug)?.createdAt || action.payload.createdAt
}
},
loading: false,
error: null
@@ -98,11 +105,11 @@ export function MangaProvider({ children }) {
const loadCollection = useCallback(async () => {
// Si nous avons déjà des données, les afficher immédiatement
if (state.collection) {
// Rafraîchir en arrière-plan si les données sont vieilles de plus de 1 minute
// Rafraîchir en arrière-plan si les données sont vieilles de plus de 30 secondes
const isStale = state.lastCollectionUpdate &&
(Date.now() - state.lastCollectionUpdate) > 60 * 1000;
(Date.now() - state.lastCollectionUpdate) > 30 * 1000;
if (isStale) {
if (isStale && !state.isBackgroundLoading) {
refreshCollectionInBackground();
}
return;
@@ -116,7 +123,7 @@ export function MangaProvider({ children }) {
dispatch({ type: 'SET_ERROR', payload: 'Failed to load manga collection' });
console.error(error);
}
}, [state.collection, state.lastCollectionUpdate, refreshCollectionInBackground]);
}, [state.collection, state.lastCollectionUpdate, state.isBackgroundLoading, refreshCollectionInBackground]);
const loadMangaDetail = useCallback(async (slug) => {
// Retourner les données en cache si disponibles