Compare commits
No commits in common. "1524154bfbd8ed09f26a5c49692d862bc85215d6" and "50c08286404d528b99991ec486beee3f582c54ab" have entirely different histories.
1524154bfb
...
50c0828640
1 changed files with 22 additions and 21 deletions
|
@ -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[]>(
|
||||||
method: "GET",
|
`${config.public.apiURL}/movies/search?q=${searchTerm}`,
|
||||||
headers: {
|
{
|
||||||
"Content-type": "application/json",
|
method: "GET",
|
||||||
Authorization: `Token ${useCookie("token").value}`,
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
);
|
||||||
.then((data) => {
|
|
||||||
movies.value = data;
|
if (error.value) {
|
||||||
loading.value = false;
|
if (error.value.statusCode === 401) {
|
||||||
})
|
alert("Unauthorized");
|
||||||
.catch((err) => {
|
}
|
||||||
if (err.statusCode === 401) {
|
} else {
|
||||||
navigateTo("/login");
|
if (!data.value) {
|
||||||
} else if (err.statusCode === 404) {
|
alert("No movies found.");
|
||||||
alert("No movies found");
|
} else {
|
||||||
loading.value = false;
|
movies.value = data.value || [];
|
||||||
} else {
|
}
|
||||||
alert("An error occurred. Please try again later.");
|
}
|
||||||
}
|
loading.value = false;
|
||||||
});
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue