diff --git a/frontend/src/components/Gallery/AppBar/Search/SearchTextField.vue b/frontend/src/components/Gallery/AppBar/Search/SearchTextField.vue index 738c2b3e9..18648bcb5 100644 --- a/frontend/src/components/Gallery/AppBar/Search/SearchTextField.vue +++ b/frontend/src/components/Gallery/AppBar/Search/SearchTextField.vue @@ -61,45 +61,44 @@ function setFilters() { ]); } -function fetchRoms() { +async function fetchRoms() { if (searchText.value) { // Auto hide android keyboard const inputElement = document.getElementById("search-text-field"); inputElement?.blur(); gettingRoms.value = true; - romApi - .getRoms({ searchTerm: searchText.value }) - .then(({ data }) => { - data = data.sort((a, b) => { - return a.platform_name.localeCompare(b.platform_name); - }); - romsStore.set(data); - romsStore.setFiltered(data, galleryFilterStore); - }) - .catch((error) => { - emitter?.emit("snackbarShow", { - msg: `Couldn't fetch roms: ${error}`, - icon: "mdi-close-circle", - color: "red", - timeout: 4000, - }); - console.error(`Couldn't fetch roms: ${error}`); - }) - .finally(() => { - gettingRoms.value = false; + + try { + const { data } = await romApi.getRoms({ searchTerm: searchText.value }); + const sortedData = data.sort((a, b) => { + return a.platform_name.localeCompare(b.platform_name); }); - galleryFilterStore.setFilterPlatforms([ - ...new Map( - romsStore.filteredRoms.map((rom) => { - const platform = allPlatforms.value.find( - (p) => p.id === rom.platform_id, - ); - return [rom.platform_name, platform]; - }), - ).values(), - ] as Platform[]); - setFilters(); - galleryFilterStore.activeFilterDrawer = false; + romsStore.set(sortedData); + romsStore.setFiltered(sortedData, galleryFilterStore); + } catch (error) { + emitter?.emit("snackbarShow", { + msg: `Couldn't fetch roms: ${error}`, + icon: "mdi-close-circle", + color: "red", + timeout: 4000, + }); + console.error(`Couldn't fetch roms: ${error}`); + } finally { + gettingRoms.value = false; + + galleryFilterStore.setFilterPlatforms([ + ...new Map( + romsStore.filteredRoms.map((rom) => { + const platform = allPlatforms.value.find( + (p) => p.id === rom.platform_id, + ); + return [rom.platform_name, platform]; + }), + ).values(), + ] as Platform[]); + setFilters(); + galleryFilterStore.activeFilterDrawer = false; + } } } diff --git a/frontend/src/views/Gallery/Collection.vue b/frontend/src/views/Gallery/Collection.vue index 860a4242f..d031f97a3 100644 --- a/frontend/src/views/Gallery/Collection.vue +++ b/frontend/src/views/Gallery/Collection.vue @@ -53,34 +53,37 @@ async function fetchRoms() { scrim: false, }); - await romApi - .getRoms({ + try { + const { data } = await romApi.getRoms({ collectionId: romsStore.currentCollection?.id, searchTerm: normalizeString(galleryFilterStore.filterText), - }) - .then(({ data }) => { - romsStore.set(data); - romsStore.setFiltered(data, galleryFilterStore); - }) - .catch((error) => { - emitter?.emit("snackbarShow", { - msg: `Couldn't fetch roms for collection ID ${currentCollection.value?.id}: ${error}`, - icon: "mdi-close-circle", - color: "red", - timeout: 4000, - }); - console.error( - `Couldn't fetch roms for collection ID ${currentCollection.value?.id}: ${error}`, - ); - noCollectionError.value = true; - }) - .finally(() => { - gettingRoms.value = false; - emitter?.emit("showLoadingDialog", { - loading: gettingRoms.value, - scrim: false, - }); }); + romsStore.set(data); + romsStore.setFiltered(data, galleryFilterStore); + + gettingRoms.value = false; + emitter?.emit("showLoadingDialog", { + loading: gettingRoms.value, + scrim: false, + }); + } catch (error) { + emitter?.emit("snackbarShow", { + msg: `Couldn't fetch roms for collection ID ${currentCollection.value?.id}: ${error}`, + icon: "mdi-close-circle", + color: "red", + timeout: 4000, + }); + console.error( + `Couldn't fetch roms for collection ID ${currentCollection.value?.id}: ${error}`, + ); + noCollectionError.value = true; + } finally { + gettingRoms.value = false; + emitter?.emit("showLoadingDialog", { + loading: gettingRoms.value, + scrim: false, + }); + } } function setFilters() { @@ -216,7 +219,7 @@ onMounted(async () => { watch( () => allCollections.value, - (collections) => { + async (collections) => { if ( collections.length > 0 && collections.some((collection) => collection.id === routeCollectionId) @@ -233,7 +236,7 @@ onMounted(async () => { ) { romsStore.setCurrentCollection(collection); resetGallery(); - fetchRoms(); + await fetchRoms(); setFilters(); } @@ -256,7 +259,7 @@ onBeforeRouteUpdate(async (to, from) => { watch( () => allCollections.value, - (collections) => { + async (collections) => { if (collections.length > 0) { const collection = collections.find( (collection) => collection.id === routeCollectionId, @@ -269,7 +272,7 @@ onBeforeRouteUpdate(async (to, from) => { collection ) { romsStore.setCurrentCollection(collection); - fetchRoms(); + await fetchRoms(); setFilters(); } } diff --git a/frontend/src/views/Gallery/Platform.vue b/frontend/src/views/Gallery/Platform.vue index 62d8ada98..49a73c59e 100644 --- a/frontend/src/views/Gallery/Platform.vue +++ b/frontend/src/views/Gallery/Platform.vue @@ -44,7 +44,7 @@ const emitter = inject>("emitter"); emitter?.on("filter", onFilterChange); // Functions -function fetchRoms() { +async function fetchRoms() { if (gettingRoms.value) return; gettingRoms.value = true; @@ -53,34 +53,32 @@ function fetchRoms() { scrim: false, }); - romApi - .getRoms({ + try { + const { data } = await romApi.getRoms({ platformId: romsStore.currentPlatform?.id, searchTerm: normalizeString(galleryFilterStore.filterText), - }) - .then(({ data }) => { - romsStore.set(data); - romsStore.setFiltered(data, galleryFilterStore); - }) - .catch((error) => { - emitter?.emit("snackbarShow", { - msg: `Couldn't fetch roms for platform ID ${currentPlatform.value?.id}: ${error}`, - icon: "mdi-close-circle", - color: "red", - timeout: 4000, - }); - console.error( - `Couldn't fetch roms for platform ID ${currentPlatform.value?.id}: ${error}`, - ); - noPlatformError.value = true; - }) - .finally(() => { - gettingRoms.value = false; - emitter?.emit("showLoadingDialog", { - loading: gettingRoms.value, - scrim: false, - }); }); + + romsStore.set(data); + romsStore.setFiltered(data, galleryFilterStore); + } catch (error) { + emitter?.emit("snackbarShow", { + msg: `Couldn't fetch roms for platform ID ${currentPlatform.value?.id}: ${error}`, + icon: "mdi-close-circle", + color: "red", + timeout: 4000, + }); + console.error( + `Couldn't fetch roms for platform ID ${currentPlatform.value?.id}: ${error}`, + ); + noPlatformError.value = true; + } finally { + gettingRoms.value = false; + emitter?.emit("showLoadingDialog", { + loading: gettingRoms.value, + scrim: false, + }); + } } function setFilters() { @@ -225,7 +223,7 @@ onMounted(async () => { watch( () => allPlatforms.value, - (platforms) => { + async (platforms) => { if (platforms.length > 0) { if (platforms.some((platform) => platform.id === routePlatformId)) { const platform = platforms.find( @@ -240,7 +238,7 @@ onMounted(async () => { ) { romsStore.setCurrentPlatform(platform); resetGallery(); - fetchRoms(); + await fetchRoms(); setFilters(); } @@ -274,7 +272,7 @@ onBeforeRouteUpdate(async (to, from) => { watch( () => allPlatforms.value, - (platforms) => { + async (platforms) => { if (platforms.length > 0) { const platform = platforms.find( (platform) => platform.id === routePlatformId, @@ -287,7 +285,7 @@ onBeforeRouteUpdate(async (to, from) => { platform ) { romsStore.setCurrentPlatform(platform); - fetchRoms(); + await fetchRoms(); setFilters(); } else { noPlatformError.value = true;