2022-07-14 06:03:55 +02:00
|
|
|
<template>
|
|
|
|
<section class="section">
|
|
|
|
<header class="is-flex mb-6">
|
|
|
|
<h1 class="title is-2 mr-5 mb-0">Calendrier</h1>
|
|
|
|
<span class="mr-3">Séances</span>
|
|
|
|
<div class="tabs is-toggle is-small">
|
|
|
|
<ul>
|
|
|
|
<li :class="isPast ? 'is-active' : undefined">
|
2022-12-31 03:59:18 +01:00
|
|
|
<a @click="changeView('past')">
|
2022-07-14 06:03:55 +02:00
|
|
|
<span>passées</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li :class="isPast ? undefined : 'is-active'">
|
2022-12-31 03:59:18 +01:00
|
|
|
<a @click="changeView('future')">
|
2022-07-14 06:03:55 +02:00
|
|
|
<span>à venir</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</header>
|
2022-12-31 03:59:18 +01:00
|
|
|
<MovieCardListPerMonth :films-by-month="filmsByMonth" />
|
|
|
|
<Pagination
|
|
|
|
:model-value="currentPage"
|
|
|
|
:max="totalPages"
|
|
|
|
@update:model-value="changePage"
|
|
|
|
/>
|
2022-07-14 06:03:55 +02:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-12-31 03:59:18 +01:00
|
|
|
import { FilmsByMonth, PaginatedResponse } from "~/composables/types"
|
|
|
|
|
2022-12-30 22:34:43 +01:00
|
|
|
useHead({ title: "Calendrier" })
|
2022-07-14 06:03:55 +02:00
|
|
|
const router = useRouter()
|
|
|
|
const route = useRoute()
|
|
|
|
|
2022-12-31 03:59:18 +01:00
|
|
|
const currentPage = ref<number>(parseInt(route.query?.page as string) || 1)
|
|
|
|
const totalPages = ref<number>(1)
|
|
|
|
const currentView = ref<string>((route.query?.view as string) || "future")
|
|
|
|
const isPast = computed<boolean>(() => currentView.value === "past")
|
|
|
|
|
|
|
|
const filmsByMonth = ref<FilmsByMonth[]>([])
|
|
|
|
|
|
|
|
async function changePage(newPage: number) {
|
|
|
|
await loadFilms(newPage, isPast.value)
|
|
|
|
router.replace({ query: { ...route.query, page: currentPage.value } })
|
|
|
|
}
|
|
|
|
|
|
|
|
async function changeView(newView: string) {
|
|
|
|
await loadFilms(1, newView === "past")
|
|
|
|
currentView.value = newView
|
|
|
|
router.replace({ query: { view: newView } })
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadFilms(currentPage.value, isPast.value)
|
|
|
|
|
|
|
|
async function loadFilms(page = 1, isPast = false) {
|
|
|
|
const res = (
|
|
|
|
await apiGet<PaginatedResponse<FilmsByMonth>>(`films/calendar/`, {
|
|
|
|
period: isPast ? "past" : "future",
|
|
|
|
page: page,
|
|
|
|
})
|
|
|
|
).data.value
|
|
|
|
filmsByMonth.value = res?.results || []
|
|
|
|
totalPages.value = res?.totalPages || 1
|
|
|
|
currentPage.value = res?.currentPage || 1
|
|
|
|
}
|
2022-07-14 06:03:55 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="sass">
|
|
|
|
header
|
|
|
|
align-items: center
|
|
|
|
</style>
|