Compare commits

..

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

View file

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