@@ -3,33 +3,28 @@ import type { PageSize, PaginationMode, ViewMode } from '#shared/types/preferenc
33import { PAGE_SIZE_OPTIONS } from ' #shared/types/preferences'
44
55const props = defineProps <{
6- mode: PaginationMode
7- pageSize: PageSize
8- currentPage: number
96 totalItems: number
107 /** When in table view, force pagination mode (no infinite scroll for tables) */
118 viewMode? : ViewMode
129}>()
1310
11+ const mode = defineModel <PaginationMode >(' mode' , { required: true })
12+ const pageSize = defineModel <PageSize >(' pageSize' , { required: true })
13+ const currentPage = defineModel <number >(' currentPage' , { required: true })
14+
1415// Whether we should show pagination controls (table view always uses pagination)
15- const shouldShowControls = computed (() => props .viewMode === ' table' || props . mode === ' paginated' )
16+ const shouldShowControls = computed (() => props .viewMode === ' table' || mode . value === ' paginated' )
1617
1718// Table view forces pagination mode, otherwise use the provided mode
1819const effectiveMode = computed <PaginationMode >(() =>
1920 shouldShowControls .value ? ' paginated' : ' infinite' ,
2021)
2122
22- const emit = defineEmits <{
23- ' update:mode' : [mode : PaginationMode ]
24- ' update:pageSize' : [size : PageSize ]
25- ' update:currentPage' : [page : number ]
26- }>()
27-
2823// When 'all' is selected, there's only 1 page with everything
29- const isShowingAll = computed (() => props . pageSize === ' all' )
30- const effectivePageSize = computed (() => (isShowingAll .value ? props .totalItems : props . pageSize ))
24+ const isShowingAll = computed (() => pageSize . value === ' all' )
25+ const effectivePageSize = computed (() => (isShowingAll .value ? props .totalItems : pageSize . value ))
3126const totalPages = computed (() =>
32- isShowingAll .value ? 1 : Math .ceil (props .totalItems / (props . pageSize as number )),
27+ isShowingAll .value ? 1 : Math .ceil (props .totalItems / (pageSize . value as number )),
3328)
3429
3530// Whether to show the mode toggle (hidden in table view since table always uses pagination)
@@ -38,39 +33,39 @@ const showModeToggle = computed(() => props.viewMode !== 'table')
3833const startItem = computed (() => {
3934 if (props .totalItems === 0 ) return 0
4035 if (isShowingAll .value ) return 1
41- return (props . currentPage - 1 ) * (props . pageSize as number ) + 1
36+ return (currentPage . value - 1 ) * (pageSize . value as number ) + 1
4237})
4338
4439const endItem = computed (() => {
4540 if (isShowingAll .value ) return props .totalItems
46- return Math .min (props . currentPage * (props . pageSize as number ), props .totalItems )
41+ return Math .min (currentPage . value * (pageSize . value as number ), props .totalItems )
4742})
4843
49- const canGoPrev = computed (() => props . currentPage > 1 )
50- const canGoNext = computed (() => props . currentPage < totalPages .value )
44+ const canGoPrev = computed (() => currentPage . value > 1 )
45+ const canGoNext = computed (() => currentPage . value < totalPages .value )
5146
5247function goToPage(page : number ) {
5348 if (page >= 1 && page <= totalPages .value ) {
54- emit ( ' update: currentPage' , page )
49+ currentPage . value = page
5550 }
5651}
5752
5853function goPrev() {
5954 if (canGoPrev .value ) {
60- emit ( ' update: currentPage' , props . currentPage - 1 )
55+ currentPage . value = currentPage . value - 1
6156 }
6257}
6358
6459function goNext() {
6560 if (canGoNext .value ) {
66- emit ( ' update: currentPage' , props . currentPage + 1 )
61+ currentPage . value = currentPage . value + 1
6762 }
6863}
6964
7065// Generate visible page numbers with ellipsis
7166const visiblePages = computed (() => {
7267 const total = totalPages .value
73- const current = props . currentPage
68+ const current = currentPage . value
7469 const pages: (number | ' ellipsis' )[] = []
7570
7671 if (total <= 7 ) {
@@ -112,9 +107,9 @@ function handlePageSizeChange(event: Event) {
112107 const value = target .value
113108 // Handle 'all' as a special string value, otherwise parse as number
114109 const newSize = (value === ' all' ? ' all' : Number (value )) as PageSize
115- emit ( ' update: pageSize' , newSize )
110+ pageSize . value = newSize
116111 // Reset to page 1 when changing page size
117- emit ( ' update: currentPage' , 1 )
112+ currentPage . value = 1
118113}
119114 </script >
120115
@@ -138,7 +133,7 @@ function handlePageSizeChange(event: Event) {
138133 class =" px-2.5 py-1 text-xs font-mono rounded-sm transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-fg focus-visible:ring-offset-1"
139134 :class =" mode === 'infinite' ? 'bg-bg-muted text-fg' : 'text-fg-muted hover:text-fg'"
140135 :aria-pressed =" mode === 'infinite'"
141- @click =" emit('update: mode', 'infinite') "
136+ @click =" mode = 'infinite'"
142137 >
143138 {{ $t('filters.pagination.infinite') }}
144139 </button >
@@ -147,7 +142,7 @@ function handlePageSizeChange(event: Event) {
147142 class =" px-2.5 py-1 text-xs font-mono rounded-sm transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-fg focus-visible:ring-offset-1"
148143 :class =" mode === 'paginated' ? 'bg-bg-muted text-fg' : 'text-fg-muted hover:text-fg'"
149144 :aria-pressed =" mode === 'paginated'"
150- @click =" emit('update: mode', 'paginated') "
145+ @click =" mode = 'paginated'"
151146 >
152147 {{ $t('filters.pagination.paginated') }}
153148 </button >
0 commit comments