2025-03-30 20:51:11 -05:00
|
|
|
<template>
|
|
|
|
<div v-if="list_id !== 0" class="p-5 sm:p-0">
|
2025-04-13 01:39:23 -05:00
|
|
|
<Modal ref="movie_modal">
|
2025-04-13 22:23:09 -05:00
|
|
|
<ShowMovie
|
|
|
|
v-if="modal_movie"
|
|
|
|
:movie="modal_movie"
|
|
|
|
@close-modal="closeModal"
|
|
|
|
></ShowMovie>
|
2025-03-30 20:51:11 -05:00
|
|
|
</Modal>
|
|
|
|
<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>
|
|
|
|
<ul class="flex flex-row">
|
|
|
|
<li>
|
|
|
|
<label class="mr-2" for="hide_scheduled">Hide Scheduled</label>
|
|
|
|
<input
|
2025-04-07 21:10:06 -05:00
|
|
|
id="hide_scheduled"
|
|
|
|
v-model="hide_scheduled"
|
|
|
|
type="checkbox"
|
|
|
|
@change="hideScheduled"
|
|
|
|
/>
|
2025-03-30 20:51:11 -05:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2025-04-07 21:10:06 -05:00
|
|
|
<input
|
|
|
|
v-model="movie_query"
|
|
|
|
class="p-1 rounded"
|
|
|
|
placeholder="Filter Movies"
|
|
|
|
type="text"
|
|
|
|
@input="filterMovies"
|
2025-03-30 20:51:11 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- MOVIE LIST -->
|
2025-04-07 21:10:06 -05:00
|
|
|
<ul
|
|
|
|
class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 mt-5"
|
|
|
|
>
|
|
|
|
<li
|
|
|
|
v-for="movie in filtered_movies"
|
|
|
|
:key="movie.id"
|
|
|
|
class="rounded movie-card neon-border"
|
|
|
|
>
|
2025-03-30 20:51:11 -05:00
|
|
|
<!-- POSTER -->
|
|
|
|
<img
|
2025-04-07 21:10:06 -05:00
|
|
|
:data-src="movie.poster"
|
|
|
|
alt="movie poster"
|
|
|
|
class="lazyload p-3 movie-poster hover-pointer mx-auto"
|
|
|
|
@click="showModal(movie)"
|
2025-03-30 20:51:11 -05:00
|
|
|
/>
|
|
|
|
<div class="p-5 flex flex-col">
|
|
|
|
<!-- TITLE -->
|
|
|
|
<span class="font-bold text-center mb-1">{{ movie.title }}</span>
|
2025-04-07 21:10:06 -05:00
|
|
|
<span
|
|
|
|
v-if="logged_in"
|
|
|
|
class="text-center hover-pointer"
|
2025-04-19 14:48:48 -05:00
|
|
|
@click="removeMovie(movie.imdb_id)"
|
2025-04-07 21:10:06 -05:00
|
|
|
>
|
2025-03-30 20:51:11 -05:00
|
|
|
X
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2025-04-07 21:10:06 -05:00
|
|
|
<script lang="ts" setup>
|
2025-03-30 20:51:11 -05:00
|
|
|
import ShowMovie from "~/components/modal-content/ShowMovie.vue";
|
2025-04-07 21:10:06 -05:00
|
|
|
import "lazysizes";
|
|
|
|
import type { MovieList } from "~/types/movielist";
|
|
|
|
import type { Movie } from "~/types/movie";
|
2025-04-13 01:39:23 -05:00
|
|
|
import Modal from "~/components/Modal.vue";
|
|
|
|
|
2025-04-07 21:10:06 -05:00
|
|
|
const list_id = ref(0);
|
|
|
|
const list = defineModel<MovieList>("movie_list", { default: [] });
|
|
|
|
const modal_movie: Ref<Movie | null> = ref(null);
|
|
|
|
const movies = defineModel<Movie[] | []>("movies", {
|
|
|
|
default: [],
|
|
|
|
});
|
|
|
|
const filtered_movies = defineModel<Movie[]>("filtered_movies");
|
|
|
|
const movie_query = ref("");
|
|
|
|
const logged_in = ref(false);
|
|
|
|
const hide_scheduled = ref(false);
|
|
|
|
|
|
|
|
const getList = async function (list_id: number) {
|
|
|
|
let config = useRuntimeConfig();
|
2025-04-19 14:48:48 -05:00
|
|
|
$fetch<MovieList>(`${config.public.apiURL}/lists/${list_id}`, {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"Content-type": "application/json",
|
|
|
|
Authorization: `Token ${useCookie("token").value}`,
|
2025-03-30 20:51:11 -05:00
|
|
|
},
|
2025-04-19 14:48:48 -05:00
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
list.value = data;
|
|
|
|
movies.value = data?.movies || [];
|
2025-04-07 21:10:06 -05:00
|
|
|
filtered_movies.value = movies.value;
|
2025-04-19 14:48:48 -05:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
if (err.statusCode === 401) {
|
|
|
|
navigateTo("/");
|
|
|
|
}
|
|
|
|
if (err.statusCode === 404) {
|
|
|
|
alert("List not found");
|
|
|
|
navigateTo("/lists");
|
|
|
|
}
|
|
|
|
});
|
2025-04-07 21:10:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const hideScheduled = function () {
|
|
|
|
if (hide_scheduled && movies.value.length > 0) {
|
|
|
|
let filtered = movies.value.filter((movie) => {
|
|
|
|
return movie.last_watched === null;
|
|
|
|
});
|
|
|
|
if (typeof filtered != "undefined") {
|
|
|
|
filtered_movies.value = filtered;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
filtered_movies.value = movies.value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-04-19 14:48:48 -05:00
|
|
|
const removeMovie = async function (movie_id: string) {
|
2025-04-07 21:10:06 -05:00
|
|
|
let config = useRuntimeConfig();
|
|
|
|
let confirmed = confirm("Remove movie from list?");
|
|
|
|
|
|
|
|
if (!confirmed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { data, error } = await useFetch<MovieList>(
|
|
|
|
`${config.public.apiURL}/lists/${list_id.value}/movie/${movie_id}/`,
|
|
|
|
{
|
|
|
|
method: "DELETE",
|
|
|
|
headers: {
|
|
|
|
"Content-type": "application/json",
|
|
|
|
Authorization: `Token ${useCookie("token").value}`,
|
|
|
|
},
|
2025-03-30 20:51:11 -05:00
|
|
|
},
|
2025-04-07 21:10:06 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
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;
|
2025-03-30 20:51:11 -05:00
|
|
|
}
|
|
|
|
}
|
2025-04-07 21:10:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const filterMovies = function () {
|
|
|
|
if (!movie_query) {
|
|
|
|
filtered_movies.value = movies.value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
filtered_movies.value = movies.value.filter((movie) => {
|
|
|
|
return (
|
|
|
|
movie.title.toLowerCase().search(movie_query.value.toLowerCase()) > -1
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2025-03-30 20:51:11 -05:00
|
|
|
|
2025-04-07 21:10:06 -05:00
|
|
|
const showModal = function (movie: Movie) {
|
|
|
|
modal_movie.value = movie;
|
2025-04-13 01:39:23 -05:00
|
|
|
movie_modal.value?.toggleModal();
|
2025-04-07 21:10:06 -05:00
|
|
|
};
|
|
|
|
|
2025-04-13 22:23:09 -05:00
|
|
|
const movie_modal = ref<InstanceType<typeof Modal> | null>(null);
|
|
|
|
const closeModal = function (movie: Movie) {
|
|
|
|
movie_modal.value?.toggleModal();
|
|
|
|
};
|
|
|
|
|
2025-04-07 21:10:06 -05:00
|
|
|
onMounted(() => {
|
|
|
|
const route = useRoute();
|
|
|
|
if (typeof route.params.id === "string") {
|
|
|
|
const list_param: string = route.params.id;
|
|
|
|
list_id.value = parseInt(list_param);
|
|
|
|
getList(list_id.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
const token = useCookie("token").value;
|
|
|
|
if (token) {
|
|
|
|
logged_in.value = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2025-03-30 20:51:11 -05:00
|
|
|
|
2025-04-07 21:10:06 -05:00
|
|
|
<style scoped></style>
|