Refactor useCoffeePictures to handle loading state and picture URLs more effectively

This commit is contained in:
seaznCode 2026-05-05 22:10:07 +02:00
parent a01bf24928
commit 6441a39e71

View File

@ -40,7 +40,6 @@ export function useCoffeePictures(coffeeId?: string) {
useEffect(() => {
if (!coffeeId) {
setPictureUrls([]);
return;
}
@ -51,9 +50,10 @@ export function useCoffeePictures(coffeeId?: string) {
];
let isCancelled = false;
setLoading(true);
const loadPictures = async () => {
if (!isCancelled) setLoading(true);
for (const url of candidateUrls) {
try {
const response = await authFetch(url, {
@ -105,5 +105,8 @@ export function useCoffeePictures(coffeeId?: string) {
};
}, [coffeeId]);
return { pictureUrls, loading };
return {
pictureUrls: coffeeId ? pictureUrls : [],
loading: coffeeId ? loading : false,
};
}