@@ -24,6 +24,7 @@ import type { Metadata } from 'next'
2424import { SITE_NAME } from '@/lib/consts'
2525import { DropdownMenuBorrow } from '@/components/borrows/DropdownMenuBorrow'
2626import { BtnScanReturnBorrow } from '@/components/borrows/ModalReturnBorrow'
27+ import { TabLink } from '@/components/borrows/TabLink'
2728
2829export const metadata : Metadata = {
2930 title : `Borrows · ${ SITE_NAME } ` ,
@@ -33,15 +34,17 @@ export default async function Borrows({
3334 searchParams,
3435} : {
3536 searchParams : Promise < {
36- skip ?: number
37- limit ?: number
37+ skip ?: string
38+ limit ?: string
3839 library_id ?: string
40+ status ?: string
3941 } >
4042} ) {
4143 const sp = await searchParams
4244 const skip = Number ( sp ?. skip ?? 0 )
4345 const limit = Number ( sp ?. limit ?? 20 )
4446 const library_id = sp ?. library_id
47+ const status = sp ?. status as 'active' | 'overdue' | 'returned'
4548
4649 const headers = await Verify ( {
4750 from : '/borrows' ,
@@ -53,6 +56,7 @@ export default async function Borrows({
5356 sort_in : 'desc' ,
5457 limit : limit ,
5558 skip : skip ,
59+ status,
5660 ...( library_id ? { library_id } : { } ) ,
5761 } ,
5862 {
@@ -66,8 +70,16 @@ export default async function Borrows({
6670
6771 const prevSkip = skip - limit > 0 ? skip - limit : 0
6872
69- const nextURL = `/borrows?skip=${ skip + limit } &limit=${ limit } `
70- const prevURL = `/borrows?skip=${ prevSkip } &limit=${ limit } `
73+ // Build next and previous URLs, preserving existing search params except skip/limit
74+ const nextParams = new URLSearchParams ( sp )
75+ nextParams . set ( 'skip' , String ( skip + limit ) )
76+ nextParams . set ( 'limit' , String ( limit ) )
77+ const nextURL = `/borrows?${ nextParams . toString ( ) } `
78+
79+ const prevParams = new URLSearchParams ( sp )
80+ prevParams . set ( 'skip' , String ( prevSkip ) )
81+ prevParams . set ( 'limit' , String ( limit ) )
82+ const prevURL = `/borrows?${ prevParams . toString ( ) } `
7183
7284 return (
7385 < div className = "space-y-4" >
@@ -107,6 +119,17 @@ export default async function Borrows({
107119 </ div >
108120 </ div >
109121 </ nav >
122+ < div className = "" >
123+ < TabLink
124+ tabs = { [
125+ { name : 'All' , href : '/borrows' } ,
126+ { name : 'Active' , href : '/borrows?status=active' } ,
127+ { name : 'Overdue' , href : '/borrows?status=overdue' } ,
128+ { name : 'Returned' , href : '/borrows?status=returned' } ,
129+ ] }
130+ activeHref = { `/borrows${ status ? `?status=${ status } ` : '' } ` }
131+ />
132+ </ div >
110133 < div className = "grid gap-4 md:grid-cols-2 lg:grid-cols-3" >
111134 { res . data . map ( ( borrow ) => (
112135 < ListCardBorrow key = { borrow . id } borrow = { borrow } />
0 commit comments