showings-updates #3

Merged
tiradoe merged 4 commits from showings-updates into main 2025-04-18 23:49:23 +00:00
4 changed files with 92 additions and 72 deletions
Showing only changes of commit c3247883f5 - Show all commits

View file

@ -1,58 +1,69 @@
<template> <template>
<div> <div>
<form id="schedule-form" class="visually-hidden" method="post" onsubmit="return false"> <form
id="schedule-form"
class="visually-hidden"
method="post"
onsubmit="return false"
>
<!-- SCHEDULE --> <!-- SCHEDULE -->
<label class="pb-1 text-start font-bold" for="schedule-date">Date</label><br/> <label class="pb-1 text-start font-bold" for="schedule-date">Date</label
<input id="schedule-input" class="rounded-l p-1" name="schedule-date" ><br />
type="date"/> <input
<button class="btn mt-5 sm:mt-0 p-1 rounded sm:rounded-none sm:rounded-r" type="button" @click="schedule">Schedule id="schedule-input"
class="rounded-l p-1"
name="schedule-date"
type="date"
/>
<button
class="btn mt-5 sm:mt-0 p-1 rounded sm:rounded-none sm:rounded-r"
type="button"
@click="schedule"
>
Schedule
</button> </button>
</form> </form>
</div> </div>
</template> </template>
<script> <script lang="ts" setup>
export default { const props = defineProps(["movie"]);
name: "ScheduleMovie", const emits = defineEmits(["closeModal"]);
methods: {
schedule: function (e) { const schedule = function (e: Event) {
const config = useRuntimeConfig(); const config = useRuntimeConfig();
e.preventDefault(); e.preventDefault();
let showtime_input = document.getElementById("schedule-input").value; let showtime_input = (
document.getElementById("schedule-input") as HTMLInputElement
).value;
if (!showtime_input) { if (!showtime_input) {
alert("Please set showtime."); alert("Please set showtime.");
return false; return false;
} }
let showtime = showtime_input + " " + "00:00:00";
fetch(`${config.public.apiURL}/schedules/movie`, { const date = new Date(`${showtime_input}T00:00:00`);
credentials: "include",
fetch(`${config.public.apiURL}/showings/`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
"schedule_id": 1, schedule: 1,
"movie_id": this.movie.id, movie: props.movie.id,
"showtime": showtime, showtime: date.toISOString(),
"owner": 1, public: "False",
"public": false
}), }),
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
"token": useCookie("token").value, Authorization: `Token ${useCookie("token").value}`,
}
})
.then(response => response.json())
.then(_json => {
this.$parent.$parent.closeModal();
}
)
.catch(err => alert("Unable to schedule movie. Error:\n" + err))
}
}, },
props: ["movie"] })
} .then((response) => response.json())
.then((_json) => {
emits("closeModal");
})
.catch((err) => alert("Unable to schedule movie. Error:\n" + err));
};
</script> </script>
<style scoped> <style scoped></style>
</style>

View file

@ -5,36 +5,38 @@
{{ movie.title }} ({{ movie.year }}) {{ movie.title }} ({{ movie.year }})
</h2> </h2>
<div class="sm:inline-flex sm:space-x-5"> <div class="sm:inline-flex sm:space-x-5">
<img :src="movie.poster" alt="movie poster" class="mx-auto sm:mx-0 neon-border"/> <img
:src="movie.poster"
alt="movie poster"
class="mx-auto sm:mx-0 neon-border"
/>
<div class="pt-5 sm:pt-0"> <div class="pt-5 sm:pt-0">
<p>{{ movie.plot }}</p> <p>{{ movie.plot }}</p>
<ScheduleMovie v-if="logged_in" :movie="movie" class="mt-5"/> <ScheduleMovie
v-if="logged_in"
:movie="movie"
class="mt-5"
@close-modal="$emit('close-modal')"
/>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script lang="ts" setup>
import ScheduleMovie from "~/components/forms/ScheduleMovie.vue"; import ScheduleMovie from "~/components/forms/ScheduleMovie.vue";
export default { const props = defineProps(["movie"]);
name: "ShowMovie", const emits = defineEmits(["close-modal"]);
data: () => ({ const logged_in = ref(false);
logged_in: false,
}), onMounted(() => {
components: {ScheduleMovie},
props: ["movie"],
mounted() {
const token = useCookie("token").value; const token = useCookie("token").value;
if (token) { if (token) {
this.logged_in = true; logged_in.value = true;
} }
} });
}
</script> </script>
<style scoped> <style scoped></style>
</style>

View file

@ -1,7 +1,11 @@
<template> <template>
<div v-if="list_id !== 0" class="p-5 sm:p-0"> <div v-if="list_id !== 0" class="p-5 sm:p-0">
<Modal ref="movie_modal"> <Modal ref="movie_modal">
<ShowMovie v-if="modal_movie" :movie="modal_movie"></ShowMovie> <ShowMovie
v-if="modal_movie"
:movie="modal_movie"
@close-modal="closeModal"
></ShowMovie>
</Modal> </Modal>
<h2 class="text-xl font-bold pb-5">{{ list.name }}</h2> <h2 class="text-xl font-bold pb-5">{{ list.name }}</h2>
<div class="grid grid-cols-2 rounded movie-card neon-border p-5"> <div class="grid grid-cols-2 rounded movie-card neon-border p-5">
@ -66,8 +70,6 @@ import type { MovieList } from "~/types/movielist";
import type { Movie } from "~/types/movie"; import type { Movie } from "~/types/movie";
import Modal from "~/components/Modal.vue"; import Modal from "~/components/Modal.vue";
const movie_modal = ref<InstanceType<typeof Modal> | null>(null);
const list_id = ref(0); const list_id = ref(0);
const list = defineModel<MovieList>("movie_list", { default: [] }); const list = defineModel<MovieList>("movie_list", { default: [] });
const modal_movie: Ref<Movie | null> = ref(null); const modal_movie: Ref<Movie | null> = ref(null);
@ -182,6 +184,11 @@ const showModal = function (movie: Movie) {
movie_modal.value?.toggleModal(); movie_modal.value?.toggleModal();
}; };
const movie_modal = ref<InstanceType<typeof Modal> | null>(null);
const closeModal = function (movie: Movie) {
movie_modal.value?.toggleModal();
};
onMounted(() => { onMounted(() => {
const route = useRoute(); const route = useRoute();
if (typeof route.params.id === "string") { if (typeof route.params.id === "string") {

View file

@ -83,10 +83,10 @@ const months = [
]; ];
const formatDate = function (date_string: string) { const formatDate = function (date_string: string) {
let parsed_date = new Date(Date.parse(date_string)); let date = new Date(date_string);
let month = months[parsed_date.getMonth()]; let month = months[date.getMonth()];
return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`; return `${month} ${date.getDate()}, ${date.getFullYear()}`;
}; };
const getSchedule = async function (previous = false) { const getSchedule = async function (previous = false) {