Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Persist in query params #97

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
4 changes: 2 additions & 2 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"*.{js,jsx,ts,tsx}": [
"pnpm run lint",
"pnpm run format"
"npm run lint",
"npm run format"
]
}
8 changes: 7 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@
".github/**",
".husky/**",
".vscode/**",
"dist/**",
"coverage/**",
"playwright-report/**",
"test-results/**",
"public/**",
"node_modules/**"
"node_modules/**",
"tsconfig.app.json",
"tsconfig.json",
"tsconfig.node.json"
]
}
}
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}
}
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test';
import { defineConfig, devices } from '@playwright/test'

/**
* Read environment variables from file.
Expand Down Expand Up @@ -80,4 +80,4 @@ export default defineConfig({
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});
})
26 changes: 14 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Route, Routes } from 'react-router-dom';
import { SWRConfig } from 'swr';
import { Layout } from './components/Layout';
import { localCache } from './lib/cache';
import { About } from './views/About';
import { Detail } from './views/Detail';
import ErrorPage from './views/Error';
import { Home } from './views/Home';
import { Route, Routes } from 'react-router-dom'
import { SWRConfig } from 'swr'
import { Layout } from './components/Layout'
import { localCache } from './lib/cache'
import { About } from './views/About'
import { Detail } from './views/Detail'
import ErrorPage from './views/Error'
import { Home } from './views/Home'

export default function App() {
return (
<SWRConfig value={{
provider: localCache,
}}>
<SWRConfig
value={{
provider: localCache,
}}
>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
Expand All @@ -21,5 +23,5 @@ export default function App() {
</Route>
</Routes>
</SWRConfig>
);
)
}
10 changes: 5 additions & 5 deletions src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export function CopyButton({
disabled={isCopied}
data-copied={`${isCopied}`}
onClick={() => {
setIsCopied(true);
copyTextToClipboard(`${text}`);
setIsCopied(true)
copyTextToClipboard(`${text}`)

setTimeout(() => {
setIsCopied(false);
}, 3000);
setIsCopied(false)
}, 3000)
}}
>
{isCopied ? (
Expand All @@ -49,5 +49,5 @@ export function CopyButton({
) : null}
</Button>
</div>
);
)
}
16 changes: 8 additions & 8 deletions src/components/EmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Link } from "react-router-dom";
import { Button } from "./ui/button";
import { Link } from 'react-router-dom'
import { Button } from './ui/button'

export const EmptyState = ({
title,
subtitle,
actionLink = '/',
actionTarget = 'Back to Homepage',
}: {
title: string;
subtitle?: string;
actionTarget?: string;
actionLink?: string;
title: string
subtitle?: string
actionTarget?: string
actionLink?: string
}) => {
return (
<div className="relative py-16 max-w-4xl mx-auto flex flex-col justify-center items-center gap-8 text-center">
Expand All @@ -34,5 +34,5 @@ export const EmptyState = ({
<Link to={actionLink}>{actionTarget}</Link>
</Button>
</div>
);
};
)
}
10 changes: 5 additions & 5 deletions src/components/GhCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import GitHubCalendar from 'react-github-calendar';
import { useTheme } from './theme-provider';
import GitHubCalendar from 'react-github-calendar'
import { useTheme } from './theme-provider'

export const GhCalendar = ({ username }: { username: string }) => {
const { theme } = useTheme();
const { theme } = useTheme()

return (
<GitHubCalendar
username={username}
blockSize={16}
colorScheme={theme === 'system' ? undefined : theme}
/>
);
};
)
}
18 changes: 10 additions & 8 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Analytics } from '@vercel/analytics/react';
import { GithubIcon } from "lucide-react";
import { Link, Outlet } from "react-router-dom"
import { ModeToggle } from "./mode-toggle";
import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar";
import { Button } from "./ui/button";
import { Analytics } from '@vercel/analytics/react'
import { GithubIcon } from 'lucide-react'
import { Link, Outlet } from 'react-router-dom'
import { ModeToggle } from './mode-toggle'
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'
import { Button } from './ui/button'

export const Layout = () => {
return (
Expand Down Expand Up @@ -38,8 +38,10 @@ export const Layout = () => {
</main>
<footer className="w-full p-4 border-t">
<div className="container mx-auto text-center text-muted-foreground">
<span>© 2023, built with ☕️</span>
<br />
<span>
Since 2023, built with ☕️ by{' '}
By{' '}
<a
href="https://github.com/depapp/IndoGitHubers/graphs/contributors"
target="_blank"
Expand All @@ -53,5 +55,5 @@ export const Layout = () => {
</footer>
<Analytics />
</>
);
)
}
8 changes: 4 additions & 4 deletions src/components/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from '@/lib/utils';
import { cn } from '@/lib/utils'

export const Spinner = ({ className = '' }: { className?: string }) => {
return (
Expand All @@ -8,7 +8,7 @@ export const Spinner = ({ className = '' }: { className?: string }) => {
aria-hidden="true"
className={cn(
'inline w-10 h-10 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600',
className
className,
)}
viewBox="0 0 100 101"
fill="none"
Expand All @@ -26,5 +26,5 @@ export const Spinner = ({ className = '' }: { className?: string }) => {
<span className="sr-only">Loading...</span>
</div>
</div>
);
};
)
}
81 changes: 54 additions & 27 deletions src/components/TableUser/card-users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use client';
'use client'

import type { User } from '@/lib/api';
import { formatLastUpdated, formatNumber, makeInitial } from '@/lib/utils';
import type { User } from '@/lib/api'
import { formatLastUpdated, formatNumber, makeInitial } from '@/lib/utils'
import {
type ColumnDef,
type ColumnFiltersState,
type Row,
type SortingState,
Expand All @@ -15,24 +14,19 @@ import {
getPaginationRowModel,
getSortedRowModel,
useReactTable,
} from '@tanstack/react-table';
import { ClockIcon } from 'lucide-react';
import { Fragment, useState } from 'react';
import { Link } from 'react-router-dom';
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
import { DEFAULT_CLASSNAMES_RANK, renderRank } from './column';
import { DataTablePagination } from './data-table-pagination';
import { DataTableRowActions } from './data-table-row-actions';
import { DataTableToolbar } from './data-table-toolbar';

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
updatedAt?: Date;
}
} from '@tanstack/react-table'
import { ClockIcon } from 'lucide-react'
import { Fragment, useState } from 'react'
import { Link } from 'react-router-dom'
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'
import { DEFAULT_CLASSNAMES_RANK, renderRank } from './column'
import { DataTablePagination } from './data-table-pagination'
import { DataTableRowActions } from './data-table-row-actions'
import { DataTableToolbar } from './data-table-toolbar'
import type { DataTableProps } from './types'

function renderRowUser({ row }: { row: Row<User> }) {
const user = row.original as User;
const user = row.original as User
return (
<div className="w-full px-4 py-2 rounded gap-4 grid border-b">
<div className="flex justify-between">
Expand Down Expand Up @@ -80,17 +74,39 @@ function renderRowUser({ row }: { row: Row<User> }) {
</div>
</div>
</div>
);
)
}

export function CardUsers<TData, TValue>({
columns,
data,
updatedAt,

pageIndex,
pageSize,
setPageParams,

filterBy,
filterValue,
setFilterParams,

sortBy,
sortDir,
setSortParams,
}: DataTableProps<TData, TValue>) {
const [sorting, setSorting] = useState<SortingState>([]);
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([
{
id: filterBy,
value: filterValue,
},
])
const [sorting, setSorting] = useState<SortingState>([
{
id: sortBy,
desc: sortDir === 'desc',
},
])

const table = useReactTable({
data,
Expand All @@ -108,14 +124,18 @@ export function CardUsers<TData, TValue>({
sorting,
columnVisibility,
columnFilters,
pagination: {
pageSize: pageSize,
pageIndex: pageIndex,
},
},
initialState: {
columnVisibility: {
username: true,
name: true,
},
},
});
})

return (
<div className="grid gap-2">
Expand All @@ -125,6 +145,9 @@ export function CardUsers<TData, TValue>({
table={table}
withTableViewOptions={false}
withSortOptions={true}
filterValue={filterValue}
setFilterParams={setFilterParams}
setSortParams={setSortParams}
/>
</div>
<div className="grid gap-2">
Expand All @@ -144,7 +167,11 @@ export function CardUsers<TData, TValue>({
</div>

<div className="p-4">
<DataTablePagination table={table} withPageSize={false} />
<DataTablePagination
table={table}
withPageSize={false}
setPageParams={setPageParams}
/>
</div>
</div>

Expand All @@ -153,5 +180,5 @@ export function CardUsers<TData, TValue>({
{formatLastUpdated(updatedAt)}
</p>
</div>
);
)
}
Loading
Loading