Merge pull request 'fixed admin search loading issues and improved error handling' (#15) from admin-search-bug-fixes into main

Reviewed-on: #15
This commit is contained in:
Edward Tirado Jr 2025-06-30 20:40:08 +00:00
commit 1524154bfb

View file

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