Skip to content

Commit

Permalink
🐛 Fix empty search results
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoyadev committed Jul 18, 2024
1 parent ec24c85 commit df0e289
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/modules/app/composables/useGoogleBooksAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function useGoogleBooksAPI() {
.catch(async (err: Error) => {
console.error('🔴 Something went wrong: ', err);
throw err;
});
}) as Promise<T>;
}

async function searchBooks(searchOptions: GoogleBooksSearchOptions): Promise<Volume[]> {
Expand Down Expand Up @@ -65,11 +65,17 @@ export function useGoogleBooksAPI() {

delete searchOptions.q;
const searchParams = Object.keys(searchOptions).length
? `&${new URLSearchParams(searchOptions as Record<string, string>)}`
? `&${String(new URLSearchParams(searchOptions as Record<string, string>))}`
: '';

return doCall<VolumesSearch>(`/volumes?q=${query}${searchParams}`)
.then((res: VolumesSearch) => res.items);
.then((res: VolumesSearch) => {
if (res.totalItems) {
return res.items;
}

return [];
});
}

async function getBook(id: string): Promise<Volume> {
Expand Down

0 comments on commit df0e289

Please sign in to comment.