Skip to content

Commit

Permalink
feat: satellite table pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
HoshinoSuzumi committed Apr 21, 2024
1 parent 2baeadc commit da010ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
3 changes: 2 additions & 1 deletion app/satellites/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Main = () => {
const [filteredValue, setFilteredValue] = useState<string[]>([])
const [pagination, setPagination] = useState({
current: 1,
pageSize: 20,
pageSize: 10,
})

const [mobileLocationRefId, setMobileLocationRefId] = useState<UUID | null>(null)
Expand Down Expand Up @@ -196,6 +196,7 @@ export const Main = () => {
loading={ isSatellitesLoading }
compact={ false }
pagination={ pagination }
setPagination={ setPagination }
filteredValue={ filteredValue }
sorter={ (a, b) => {
return a.name.localeCompare(b.name)
Expand Down
25 changes: 24 additions & 1 deletion app/satellites/SatelliteTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CSSProperties, ReactNode, useState } from 'react'
import { Icon } from '@iconify-icon/react'
import { noto_sc, rubik } from '@/app/fonts'
import { IconSpinner } from '@/components/Icon/IconSpinner'
import { Button, Select, SideSheet, Tooltip } from '@douyinfe/semi-ui'
import { Button, Pagination, Select, SideSheet, Tooltip } from '@douyinfe/semi-ui'
import useSWR, { SWRConfig } from 'swr'
import { ObserverLocationStore, SatelliteSighting } from '@/types/types'
import Image from 'next/image'
Expand Down Expand Up @@ -694,6 +694,7 @@ export const SatelliteTable = ({
loading,
filteredValue,
pagination,
setPagination,
sorter,
}: {
satellites: Satellite[]
Expand All @@ -706,6 +707,7 @@ export const SatelliteTable = ({
current: number
pageSize: number
},
setPagination?: (pagination: { current: number, pageSize: number }) => void
sorter?: ((a: Satellite, b: Satellite) => number)
}) => {
// const [timestamp, setTimestamp] = useState(dayjs().unix())
Expand Down Expand Up @@ -777,6 +779,27 @@ export const SatelliteTable = ({
<caption
className={ `text-xs py-4 text-neutral-500 dark:text-neutral-400 caption-bottom ${ noto_sc.className }` }
>
<div className={ 'w-full flex justify-end' }>
<Pagination
total={ filteredSatellites.length || satellites.length }
pageSize={ pagination?.pageSize || 10 }
currentPage={ pagination?.current || 1 }
hideOnSinglePage
onPageChange={ page => {
setPagination?.({
pageSize: pagination?.pageSize || 10,
...pagination,
current: page,
})
setTimeout(() => {
window?.scrollTo({
behavior: 'smooth',
top: 0,
})
}, 200)
} }
/>
</div>
星历数据来源 <a href={ 'https://db.satnogs.org/' } target={ '_blank' }>SatNOGS DB</a> | <a
href={ 'https://ham-api.c5r.app/docs' } target={ '_blank' }>卫星过境信息计算接口</a>
</caption>
Expand Down
16 changes: 7 additions & 9 deletions components/MainDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,13 @@ export default function MainDrawer({children, nav}: {
))}
</ul>
</div>
<Tooltip content={ 'GitHub Repository' }>
<Button
icon={ <Icon icon={ 'mdi:github' } className={ 'text-2xl' }/> }
type={ 'tertiary' }
size={ 'large' }
theme={ 'borderless' }
onClick={ () => window.open('https://github.com/HoshinoSuzumi/ham-set', '_blank') }
/>
</Tooltip>
<Button
icon={ <Icon icon={ 'mdi:github' } className={ 'text-2xl' }/> }
type={ 'tertiary' }
size={ 'large' }
theme={ 'borderless' }
onClick={ () => window.open('https://github.com/HoshinoSuzumi/ham-set', '_blank') }
/>
</header>

<main className={'min-h-[calc(100vh-4rem)]'}>
Expand Down

0 comments on commit da010ba

Please sign in to comment.