Compare commits

..

No commits in common. "1524154bfbd8ed09f26a5c49692d862bc85215d6" and "50c08286404d528b99991ec486beee3f582c54ab" have entirely different histories.

View file

@ -19,7 +19,6 @@
<script lang="ts" setup>
import type { Movie } from "~/types/movie";
import "lazysizes";
const loading = ref(false);
@ -43,27 +42,29 @@ const findMovies = async function (e: Event) {
return;
}
$fetch<Movie[]>(`${config.public.apiURL}/movies/search?q=${searchTerm}`, {
method: "GET",
headers: {
"Content-type": "application/json",
Authorization: `Token ${useCookie("token").value}`,
const { data, error } = await useFetch<Movie[]>(
`${config.public.apiURL}/movies/search?q=${searchTerm}`,
{
method: "GET",
headers: {
"Content-type": "application/json",
Authorization: `Token ${useCookie("token").value}`,
},
},
})
.then((data) => {
movies.value = data;
loading.value = false;
})
.catch((err) => {
if (err.statusCode === 401) {
navigateTo("/login");
} else if (err.statusCode === 404) {
alert("No movies found");
loading.value = false;
} else {
alert("An error occurred. Please try again later.");
}
});
);
if (error.value) {
if (error.value.statusCode === 401) {
alert("Unauthorized");
}
} else {
if (!data.value) {
alert("No movies found.");
} else {
movies.value = data.value || [];
}
}
loading.value = false;
};
</script>