2021-10-31 11:21:21 +01:00
|
|
|
<template>
|
|
|
|
<nav class="pagination-center" aria-label="navigation">
|
|
|
|
<ul class="pagination">
|
|
|
|
<li class="page-prev" :class="{ disabled: !pagination.has_prev }">
|
|
|
|
<router-link
|
2022-03-13 11:22:48 +01:00
|
|
|
v-slot="{ navigate }"
|
2021-10-31 11:21:21 +01:00
|
|
|
class="page-link"
|
|
|
|
:to="{ path, query: getQuery(pagination.page, -1) }"
|
|
|
|
:disabled="!pagination.has_prev"
|
|
|
|
>
|
2022-03-13 11:22:48 +01:00
|
|
|
<slot @click="pagination.has_next ? navigate : null">
|
|
|
|
{{ $t('api.PAGINATION.PREVIOUS') }}
|
|
|
|
<i class="fa fa-chevron-left" aria-hidden="true" />
|
|
|
|
</slot>
|
2021-10-31 11:21:21 +01:00
|
|
|
</router-link>
|
|
|
|
</li>
|
|
|
|
<li
|
2021-11-02 20:26:43 +01:00
|
|
|
v-for="page in rangePagination(pagination.pages, pagination.page)"
|
2021-10-31 11:21:21 +01:00
|
|
|
:key="page"
|
|
|
|
class="page"
|
|
|
|
:class="{ active: page === pagination.page }"
|
|
|
|
>
|
2021-11-02 20:26:43 +01:00
|
|
|
<span v-if="page === '...'"> ... </span>
|
|
|
|
<router-link
|
|
|
|
v-else
|
|
|
|
class="page-link"
|
|
|
|
:to="{ path, query: getQuery(+page) }"
|
|
|
|
>
|
2021-10-31 11:21:21 +01:00
|
|
|
{{ page }}
|
|
|
|
</router-link>
|
|
|
|
</li>
|
|
|
|
<li class="page-next" :class="{ disabled: !pagination.has_next }">
|
|
|
|
<router-link
|
2022-03-13 11:22:48 +01:00
|
|
|
v-slot="{ navigate }"
|
2021-10-31 11:21:21 +01:00
|
|
|
class="page-link"
|
|
|
|
:to="{ path, query: getQuery(pagination.page, 1) }"
|
|
|
|
:disabled="!pagination.has_next"
|
|
|
|
>
|
2022-03-13 11:22:48 +01:00
|
|
|
<slot @click="pagination.has_next ? navigate : null">
|
|
|
|
{{ $t('api.PAGINATION.NEXT') }}
|
|
|
|
<i class="fa fa-chevron-right" aria-hidden="true" />
|
|
|
|
</slot>
|
2021-10-31 11:21:21 +01:00
|
|
|
</router-link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
</template>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { toRefs } from 'vue'
|
2021-10-31 11:21:21 +01:00
|
|
|
|
2022-03-13 10:52:10 +01:00
|
|
|
import { IPagination, TPaginationPayload } from '@/types/api'
|
2022-05-28 16:16:36 +02:00
|
|
|
import { IOauth2ClientsPayload } from '@/types/oauth'
|
2021-11-10 21:19:27 +01:00
|
|
|
import { TWorkoutsPayload } from '@/types/workouts'
|
2021-11-02 20:26:43 +01:00
|
|
|
import { rangePagination } from '@/utils/api'
|
2021-10-31 11:21:21 +01:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
|
|
|
pagination: IPagination
|
|
|
|
path: string
|
2022-05-28 16:16:36 +02:00
|
|
|
query: TWorkoutsPayload | TPaginationPayload | IOauth2ClientsPayload
|
2021-11-10 21:19:27 +01:00
|
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
|
|
|
|
|
|
|
const { pagination, path, query } = toRefs(props)
|
|
|
|
|
2022-03-13 10:52:10 +01:00
|
|
|
function getQuery(
|
|
|
|
page: number,
|
|
|
|
cursor?: number
|
2022-08-27 19:23:01 +02:00
|
|
|
): TPaginationPayload | IOauth2ClientsPayload {
|
2021-11-10 21:19:27 +01:00
|
|
|
const newQuery = Object.assign({}, query.value)
|
|
|
|
newQuery.page = cursor ? page + cursor : page
|
|
|
|
return newQuery
|
|
|
|
}
|
2021-10-31 11:21:21 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-11-29 11:23:21 +01:00
|
|
|
@import '~@/scss/vars.scss';
|
2021-10-31 11:21:21 +01:00
|
|
|
|
|
|
|
.pagination-center {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
|
|
|
.pagination {
|
|
|
|
display: flex;
|
|
|
|
padding-left: 0;
|
|
|
|
list-style: none;
|
|
|
|
border-radius: 0.25rem;
|
|
|
|
|
|
|
|
.page-prev,
|
|
|
|
.page-next,
|
|
|
|
.page {
|
|
|
|
border: solid 1px var(--card-border-color);
|
|
|
|
padding: $default-padding $default-padding * 1.5;
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.disabled {
|
|
|
|
cursor: default;
|
|
|
|
a {
|
2022-03-13 11:22:48 +01:00
|
|
|
cursor: default;
|
|
|
|
pointer-events: none;
|
2021-10-31 11:21:21 +01:00
|
|
|
color: var(--disabled-color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.page {
|
|
|
|
margin-left: -1px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.page-prev {
|
|
|
|
border-top-left-radius: 5px;
|
|
|
|
border-bottom-left-radius: 5px;
|
|
|
|
}
|
|
|
|
.page-next {
|
|
|
|
border-top-right-radius: 5px;
|
|
|
|
border-bottom-right-radius: 5px;
|
|
|
|
margin-left: -1px;
|
|
|
|
}
|
2021-11-02 20:26:43 +01:00
|
|
|
.fa {
|
|
|
|
font-size: 0.8em;
|
|
|
|
padding: 0 $default-padding * 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-width: $medium-limit) {
|
|
|
|
.pagination {
|
|
|
|
.page {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2021-10-31 11:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|