Compare commits
3 commits
50c0828640
...
1524154bfb
Author | SHA1 | Date | |
---|---|---|---|
1524154bfb | |||
0adcf5dd69 | |||
270bc4767a |
1 changed files with 21 additions and 22 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
<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);
|
||||||
|
|
||||||
|
@ -42,29 +43,27 @@ const findMovies = async function (e: Event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data, error } = await useFetch<Movie[]>(
|
$fetch<Movie[]>(`${config.public.apiURL}/movies/search?q=${searchTerm}`, {
|
||||||
`${config.public.apiURL}/movies/search?q=${searchTerm}`,
|
method: "GET",
|
||||||
{
|
headers: {
|
||||||
method: "GET",
|
"Content-type": "application/json",
|
||||||
headers: {
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
"Content-type": "application/json",
|
|
||||||
Authorization: `Token ${useCookie("token").value}`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
})
|
||||||
|
.then((data) => {
|
||||||
if (error.value) {
|
movies.value = data;
|
||||||
if (error.value.statusCode === 401) {
|
loading.value = false;
|
||||||
alert("Unauthorized");
|
})
|
||||||
}
|
.catch((err) => {
|
||||||
} else {
|
if (err.statusCode === 401) {
|
||||||
if (!data.value) {
|
navigateTo("/login");
|
||||||
alert("No movies found.");
|
} else if (err.statusCode === 404) {
|
||||||
} else {
|
alert("No movies found");
|
||||||
movies.value = data.value || [];
|
loading.value = false;
|
||||||
}
|
} else {
|
||||||
}
|
alert("An error occurred. Please try again later.");
|
||||||
loading.value = false;
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue