Skip to content

Commit

Permalink
fix recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
AmiltonCabral committed Feb 12, 2025
1 parent 82b8822 commit a3b27ba
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/app/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Search() {
if (!selectedGenre || !bookTitle) {
setShowModal(true);
setSelectedBook(
"Por favor, insira tanto o gênero quanto o título do livro."
"Por favor, insira tanto o gênero quanto o título do livro.",
);
return;
}
Expand All @@ -58,10 +58,7 @@ export default function Search() {
`${url}/recommend/${selectedGenre}/${bookTitle}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
},
);

if (!response.ok) {
Expand All @@ -70,18 +67,8 @@ export default function Search() {

const text = await response.text();

let data;
try {
data = JSON.parse(text);
} catch (parseError) {
setShowModal(true);
setSelectedBook("Erro ao interpretar os dados da resposta.");
console.error("Erro ao interpretar os dados da resposta:", parseError);
return;
}

if (data.items && data.items.length > 0) {
setSelectedBook(data.items[0]);
if (text != "") {
setSelectedBook(text);
setShowModal(true);
} else {
setShowModal(true);
Expand All @@ -92,7 +79,9 @@ export default function Search() {
console.error("Erro ao buscar livros:", error);
setShowModal(true);
setSelectedBook(
error instanceof Error ? error.message : "Ocorreu um erro desconhecido."
error instanceof Error
? error.message
: "Ocorreu um erro desconhecido.",
);
}
};
Expand Down

1 comment on commit a3b27ba

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for bookhive-web ready!

✅ Preview
https://bookhive-bukzgrbon-amiltoncabrals-projects.vercel.app

Built with commit a3b27ba.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.