diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b4d0069..80cc288 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,12 +6,9 @@ - + - - - - + - { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.git.unshallow": "true", + "WebServerToolWindowFactoryState": "false", + "code.cleanup.on.save": "true", + "git-widget-placeholder": "showings-updates", + "last_opened_file_path": "/home/tiradoe/Projects/movie-night/web/src/types", + "list.type.of.created.stylesheet": "CSS", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.standard": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.standard": "", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "npm.dev.executor": "Run", + "prettierjs.PrettierConfiguration.Package": "/home/tiradoe/Projects/movie-night/web/src/node_modules/prettier", + "rearrange.code.on.save": "true", + "settings.editor.selected.configurable": "settings.vue", + "ts.external.directory.path": "/home/tiradoe/Projects/movie-night/web/src/node_modules/typescript/lib", + "vue.rearranger.settings.migration": "true" } -}]]> +} diff --git a/src/components/admin/lists.vue b/src/components/admin/lists.vue index 6925bcb..afdcc2c 100644 --- a/src/components/admin/lists.vue +++ b/src/components/admin/lists.vue @@ -3,98 +3,90 @@
- +
  • - {{ list.name }}
    - + {{ list.name }}
    +
- - + \ No newline at end of file diff --git a/src/components/admin/showings.vue b/src/components/admin/showings.vue index 07796c1..711c64b 100644 --- a/src/components/admin/showings.vue +++ b/src/components/admin/showings.vue @@ -26,7 +26,6 @@ import type { Showing } from "~/types/showing"; import { useCookie } from "#app"; import type { Schedule } from "~/types/schedule"; -import { $fetch } from "ofetch"; const showings = defineModel("showings", { default: [] }); const previous_showings = defineModel("previous_showings", { @@ -87,27 +86,33 @@ const getShowings = function (previous = false) { let params = ""; if (previous) params = "?previous=true"; - $fetch(`${config.public.apiURL}/schedules/1${params}`, { - method: "GET", - headers: { - "Content-type": "application/json", - Authorization: `Token ${useCookie("token").value}`, + const { data, error } = useFetch( + `${config.public.apiURL}/schedules/1${params}`, + { + method: "GET", + headers: { + "Content-type": "application/json", + Authorization: `Token ${useCookie("token").value}`, + }, }, - }) - .then((data) => { + ); + + if (error.value) { + if (error.value.statusCode === 401) { + alert("Unauthorized"); + } + } else { + if (!data.value) { + alert("No showings found for schedule."); + } else { if (previous) { got_previous.value = true; - previous_showings.value = data.showings; + previous_showings.value = data.value.showings; } else { - showings.value = data.showings; + showings.value = data.value.showings; } - }) - .catch((err) => { - if (err.statusCode === 401) { - useCookie("token").value = null; - navigateTo("/"); - } - }); + } + } }; diff --git a/src/pages/admin/index.vue b/src/pages/admin/index.vue index ae83bc0..9ae521a 100644 --- a/src/pages/admin/index.vue +++ b/src/pages/admin/index.vue @@ -44,7 +44,7 @@ @@ -54,14 +54,15 @@ import AddMovie from "~/components/modal-content/AddMovie.vue"; import Search from "~/components/admin/search.vue"; import Showings from "~/components/admin/showings.vue"; import Lists from "~/components/admin/lists.vue"; +import type { MovieList } from "~/types/movielist"; import { useCookie } from "#app"; import type { Movie } from "~/types/movie"; import Modal from "~/components/Modal.vue"; +const lists = defineModel("movie-lists", { default: [] }); const modal_movie = defineModel("#movie-modal"); const movie_modal = ref | null>(null); -const current_view = ref("search"); const closeModal = function () { movie_modal?.value?.toggleModal(); @@ -71,7 +72,6 @@ const showModal = function (movie: Movie) { movie_modal?.value?.toggleModal(); }; const toggleDisplay = function (element_id: string) { - if (element_id === current_view.value) return; let tabs = ["search", "showings", "lists"]; tabs.forEach((value) => { @@ -80,7 +80,6 @@ const toggleDisplay = function (element_id: string) { document .getElementById(element_id + "-tab") ?.classList.toggle("underline"); - current_view.value = element_id; } else if (!document.getElementById(value)?.classList.contains("hidden")) { document.getElementById(value)?.classList.toggle("hidden"); document.getElementById(value + "-tab")?.classList.toggle("underline"); diff --git a/src/pages/lists/[id].vue b/src/pages/lists/[id].vue index 77b717d..f59be6e 100644 --- a/src/pages/lists/[id].vue +++ b/src/pages/lists/[id].vue @@ -53,7 +53,7 @@ X @@ -83,27 +83,35 @@ const hide_scheduled = ref(false); const getList = async function (list_id: number) { let config = useRuntimeConfig(); - $fetch(`${config.public.apiURL}/lists/${list_id}`, { - method: "GET", - headers: { - "Content-type": "application/json", - Authorization: `Token ${useCookie("token").value}`, + const { data, error } = await useFetch( + `${config.public.apiURL}/lists/${list_id}`, + { + method: "GET", + headers: { + "Content-type": "application/json", + Authorization: `Token ${useCookie("token").value}`, + }, }, - }) - .then((data) => { - list.value = data; - movies.value = data?.movies || []; + ); + + if (error.value) { + if (error.value.statusCode === 401) { + navigateTo("/"); + } + if (error.value.statusCode === 404) { + alert("List not found"); + navigateTo("/lists"); + } + } else { + if (!data.value) { + alert("List not found"); + navigateTo("/lists"); + } else { + list.value = data.value; + movies.value = data.value?.movies || []; filtered_movies.value = movies.value; - }) - .catch((err) => { - if (err.statusCode === 401) { - navigateTo("/"); - } - if (err.statusCode === 404) { - alert("List not found"); - navigateTo("/lists"); - } - }); + } + } }; const hideScheduled = function () { @@ -119,7 +127,7 @@ const hideScheduled = function () { } }; -const removeMovie = async function (movie_id: string) { +const removeMovie = async function (movie_id: number) { let config = useRuntimeConfig(); let confirmed = confirm("Remove movie from list?"); diff --git a/src/pages/lists/index.vue b/src/pages/lists/index.vue index f4a38a3..55ede0e 100644 --- a/src/pages/lists/index.vue +++ b/src/pages/lists/index.vue @@ -31,19 +31,21 @@ const updateLists = async function () { headers["Authorization"] = `Token ${useCookie("token").value}`; } - await $fetch(`${config.public.apiURL}/lists`, { - method: "GET", - headers: headers, - }) - .then((data) => { - lists.value = data || []; - }) - .catch((err) => { - if (err.statusCode === 401) { - useCookie("token").value = null; - navigateTo("/"); - } - }); + const { data, error } = await useFetch( + `${config.public.apiURL}/lists`, + { + method: "GET", + headers: headers, + }, + ); + + if (error.value) { + if (error.value.statusCode === 401) { + navigateTo("/"); + } + } else { + lists.value = data.value || []; + } }; onMounted(() => { diff --git a/src/pages/schedule/index.vue b/src/pages/schedule/index.vue index 8cf2637..c373596 100644 --- a/src/pages/schedule/index.vue +++ b/src/pages/schedule/index.vue @@ -61,8 +61,6 @@