movie-night-web/src/pages/lists/index.vue

51 lines
1.2 KiB
Vue
Raw Normal View History

2025-03-30 20:51:11 -05:00
<template>
<div class="p-5 sm:p-0">
2025-04-06 17:54:59 -05:00
<div v-if="lists.length < 1">
<p>No lists found</p>
</div>
2025-03-30 20:51:11 -05:00
<ul class="grid grid-cols-2 gap-3 mt-5">
<li v-for="list in lists" class="movie-card neon-border p-5 rounded">
<div class="grid grid-rows-2 gap-3">
<NuxtLink :to="`/lists/${list.id}`" class="underline">
<h2 class="text-lg">{{ list.name }}</h2>
</NuxtLink>
2025-04-07 00:44:51 -05:00
<span>Movies: {{ list.movie_count || 0 }}</span>
2025-03-30 20:51:11 -05:00
</div>
</li>
</ul>
</div>
</template>
<script lang="ts" setup>
import type { MovieList } from "~/types/movielist";
const lists = defineModel<MovieList[]>("movie_list", { default: [] });
const updateLists = async function () {
let config = useRuntimeConfig();
2025-04-06 17:54:59 -05:00
const { data, error } = await useFetch<MovieList[]>(
`${config.public.apiURL}/lists`,
{
method: "GET",
2025-04-06 17:54:59 -05:00
headers: {
"Content-type": "application/json",
Authorization: `Token ${useCookie("token").value}`,
},
2025-03-30 20:51:11 -05:00
},
);
2025-04-07 00:44:51 -05:00
if (error.value) {
if (error.value.statusCode === 401) {
2025-04-06 17:54:59 -05:00
navigateTo("/");
}
} else {
lists.value = data.value || [];
2025-03-30 20:51:11 -05:00
}
};
2025-03-30 20:51:11 -05:00
onMounted(() => {
updateLists();
});
</script>
2025-03-30 20:51:11 -05:00
<style scoped></style>