Refactor useCoffeePictures to handle loading state and picture URLs more effectively
This commit is contained in:
parent
a01bf24928
commit
6441a39e71
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user