Skip to content

Commit

Permalink
refactor pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
l1xnan committed Feb 3, 2024
1 parent 38a7714 commit d9920ef
Show file tree
Hide file tree
Showing 12 changed files with 487 additions and 131 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-scroll-area": "^1.0.5",
Expand Down
30 changes: 30 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
--foreground: 0 0% 98%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
/* --popover: 240 10% 3.9%; */
--popover: 225, 6%, 13%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
/* --accent: 240 3.7% 15.9%; */
--accent: 205, 92%, 19%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import React, {
useState,
} from 'react';

import Dropdown from '@/components/Dropdown';
import { PaginationDropdown } from '@/components/PaginationDropdown';
import {
PageContext,
createDatasetStore,
Expand Down Expand Up @@ -181,7 +181,7 @@ function PageSizeToolbar() {
<IconButton color="inherit" onClick={decrease} disabled={page <= 1}>
<KeyboardArrowLeftIcon />
</IconButton>
<Dropdown content={content} />
<PaginationDropdown content={content} />
{count < totalCount ? `of ${totalCount}` : null}
<IconButton
color="inherit"
Expand Down
63 changes: 0 additions & 63 deletions src/components/Dropdown.tsx

This file was deleted.

55 changes: 55 additions & 0 deletions src/components/PaginationDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';

import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import {
PaginationContent,
PaginationItem,
PaginationLink,
} from '@/components/ui/pagination';
import { usePageStore } from '@/stores/dataset';

export interface DropdownProps {
content: string;
}

export function PaginationDropdown({ content }: DropdownProps) {
const { setPerPage } = usePageStore();
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<PaginationContent>
<PaginationItem>
<PaginationLink href="#" className="w-full">
{content}
<KeyboardArrowDownIcon />
</PaginationLink>
</PaginationItem>
</PaginationContent>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-32">
{[10, 100, 500, 1000].map((item) => (
<DropdownMenuItem
key={item}
className="py-1 text-xs"
onSelect={() => {
setPerPage!(item);
}}
>
{item}
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel className="py-1 text-xs">
Default: 500
</DropdownMenuLabel>
</DropdownMenuContent>
</DropdownMenu>
);
}
Loading

0 comments on commit d9920ef

Please sign in to comment.