Skip to content

Commit

Permalink
Revert "Shuffle @oxide/pagination files (#1970)"
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Feb 23, 2024
1 parent 3eebf49 commit 3ec255f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 52 deletions.
26 changes: 0 additions & 26 deletions libs/pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* Copyright Oxide Computer Company
*/
import { useState } from 'react'
import tunnel from 'tunnel-rat'

import {
Expand All @@ -30,28 +29,3 @@ export function Pagination({ inline = false, ...props }: PaginationProps) {
}

Pagination.Target = Tunnel.Out

type PageToken = string | undefined

export function usePagination() {
const [prevPages, setPrevPages] = useState<PageToken[]>([])
const [currentPage, setCurrentPage] = useState<PageToken>()

const goToPrevPage = () => {
const prevPage = prevPages.pop()
setCurrentPage(prevPage)
setPrevPages(prevPages)
}

const goToNextPage = (nextPageToken: string) => {
setPrevPages([...prevPages, currentPage])
setCurrentPage(nextPageToken)
}

return {
currentPage,
goToNextPage,
goToPrevPage,
hasPrev: prevPages.length > 0,
}
}
2 changes: 1 addition & 1 deletion libs/pagination/__tests__/use-pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { act, renderHook } from '@testing-library/react'
import { describe, expect, it } from 'vitest'

import { usePagination } from '../index.tsx'
import { usePagination } from '../use-pagination'

describe('usePagination', () => {
it('starts with empty state', () => {
Expand Down
10 changes: 10 additions & 0 deletions libs/pagination/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/

export * from './Pagination'
export * from './use-pagination'
24 changes: 0 additions & 24 deletions libs/pagination/index.tsx → libs/pagination/use-pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@
* Copyright Oxide Computer Company
*/
import { useState } from 'react'
import tunnel from 'tunnel-rat'

import {
Pagination as UIPagination,
type PaginationProps as UIPaginationProps,
} from '@oxide/ui'

const Tunnel = tunnel('pagination')

interface PaginationProps extends UIPaginationProps {
/** If true pagination will be rendered wherever `Pagination.Target` is included */
inline?: boolean
}
export function Pagination({ inline = false, ...props }: PaginationProps) {
if (inline) return <UIPagination {...props} />

return (
<Tunnel.In>
<UIPagination className="gutter h-14 py-5" {...props} />
</Tunnel.In>
)
}

Pagination.Target = Tunnel.Out

type PageToken = string | undefined

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@oxide/ui": ["libs/ui/index.ts"],
"@oxide/util": ["libs/util/index.ts"],
"@oxide/table": ["libs/table/index.ts"],
"@oxide/pagination": ["libs/pagination/index.tsx"]
"@oxide/pagination": ["libs/pagination/index.ts"]
},
"resolveJsonModule": true,
"rootDir": ".",
Expand Down

0 comments on commit 3ec255f

Please sign in to comment.