Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
88 changes: 88 additions & 0 deletions src/components/Pagination.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { useEffect } from 'react';
import styles from './Pagination.module.css';

function getVisiblePages(current, total, delta = 1) {
const pages = [];
const left = Math.max(0, current - delta);
const right = Math.min(total - 1, current + delta);

for (let i = left; i <= right; i++) {
pages.push(i);
}

return pages;
}

export default function Pagination({ page, totalPages, onChange }) {
// ⌨️ keyboard navigation
useEffect(() => {
const handler = (e) => {
if (e.key === 'ArrowRight' && page < totalPages - 1) {
onChange(page + 1);
}
if (e.key === 'ArrowLeft' && page > 0) {
onChange(page - 1);
}
};

window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, [page, totalPages, onChange]);
Comment thread
laxitajain marked this conversation as resolved.
Resolved

if (totalPages <= 1) return null;

const visiblePages = getVisiblePages(page, totalPages);

return (
<nav className={styles.pagination} aria-label="Pagination">
{/* Previous */}
<button
className={styles.arrow}
onClick={() => onChange(page - 1)}
disabled={page === 0}
aria-label="Previous page">
‹
</button>

{/* First page */}
{visiblePages[0] > 0 && (
<>
<button className={styles.page} onClick={() => onChange(0)}>
1
</button>
<span className={styles.ellipsis}>…</span>
</>
)}

{/* Visible pages */}
{visiblePages.map((p) => (
<button
key={p}
onClick={() => onChange(p)}
className={`${styles.page} ${p === page ? styles.active : ''}`}
aria-current={p === page ? 'page' : undefined}>
{p + 1}
</button>
))}

{/* Last page */}
{visiblePages.at(-1) < totalPages - 1 && (
<>
<span className={styles.ellipsis}>…</span>
<button className={styles.page} onClick={() => onChange(totalPages - 1)}>
{totalPages}
</button>
</>
)}

{/* Next */}
<button
className={styles.arrow}
onClick={() => onChange(page + 1)}
disabled={page === totalPages - 1}
aria-label="Next page">
›
</button>
</nav>
);
}
64 changes: 64 additions & 0 deletions src/components/Pagination.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 0.4rem;
margin-top: 1rem;
flex-wrap: wrap;
}

/* arrows + pages */
.arrow,
.page {
background: transparent;
border: none;
color: var(--color-text-light);
font-size: 0.95rem;
padding: 0.35rem 0.6rem;
border-radius: 6px;
cursor: pointer;
transition:
background 0.2s ease,
color 0.2s ease;
}

.arrow {
font-size: 1.2rem;
}

/* hover */
.arrow:hover,
.page:hover {
background: var(--color-glass-border);
}

/* active page */
.active {
background: var(--color-accent);
color: var(--color-text-dark);
}
Comment thread
laxitajain marked this conversation as resolved.
Resolved

/* disabled */
.arrow:disabled {
opacity: 0.4;
cursor: not-allowed;
}

/* ellipsis */
.ellipsis {
padding: 0 0.25rem;
color: var(--color-text-muted);
}

/* 📱 mobile optimization */
@media (max-width: 480px) {
.page {
min-width: 2rem;
padding: 0.3rem 0.45rem;
font-size: 0.85rem;
}

.arrow {
font-size: 1rem;
}
}
79 changes: 44 additions & 35 deletions src/pages/Credits/ContributorsCreditsCard.jsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,66 @@
import { useState, useEffect } from 'react';

Check failure on line 1 in src/pages/Credits/ContributorsCreditsCard.jsx

View workflow job for this annotation

GitHub Actions / Lint Code

'useEffect' is defined but never used. Allowed unused vars must match /^[A-Z_]/u
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
import GlassCard from '@components/GlassCard';
import contributors from '@data/contributor-credits.json';
import styles from './ContributorsCreditsCard.module.css';
import FallbackImage from '@components/FallbackImage';
import Pagination from '@components/Pagination';
import Tooltip from '@components/Tooltip';
import { User } from 'lucide-react';

export default function ContributorsCreditsCard() {
const chunk = (arr, size) =>
Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size));

const chunkSize = 13;
const chunkSize = 10;
const tables = chunk(contributors, chunkSize);

const [page, setPage] = useState(0);

return (
<GlassCard>
<h2>Contributors</h2>

<div className={styles.contributorsGrid}>
{tables.map((group, i) => (
<table key={i}>
<tbody>
{group.map((c) => (
<tr key={c.id}>
<td>
<Tooltip content={`Open ${c.login}'s GitHub profile`}>
<a href={c.html_url} target="_blank" rel="noopener noreferrer">
<FallbackImage
src={c.avatar_url}
fallback={<User color="var(--color-text-light)" />}
alt={c.login}
width="28"
height="28"
className={styles.avatar}
/>
</a>
</Tooltip>
</td>

<td>
<Tooltip content={`Visit ${c.login}'s GitHub profile`}>
<a href={c.html_url} target="_blank" rel="noopener noreferrer">
{c.login}
</a>
</Tooltip>
</td>

<td>{c.contributions} commits</td>
</tr>
))}
</tbody>
</table>
))}
{tables.map(
(group, i) =>
i === page && (
<table key={i}>
<tbody>
{group.map((c) => (
<tr key={c.id}>
<td>
<Tooltip content={`Open ${c.login}'s GitHub profile`}>
<a href={c.html_url} target="_blank" rel="noopener noreferrer">
<FallbackImage
src={c.avatar_url}
fallback={<User color="var(--color-text-light)" />}
alt={c.login}
width="28"
height="28"
className={styles.avatar}
/>
</a>
</Tooltip>
</td>

<td>
<Tooltip content={`Visit ${c.login}'s GitHub profile`}>
<a href={c.html_url} target="_blank" rel="noopener noreferrer">
{c.login}
</a>
</Tooltip>
</td>

<td>{c.contributions} commits</td>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
</tr>
))}
</tbody>
</table>
)
)}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
</div>

<Pagination page={page} totalPages={tables.length} onChange={setPage} />
</GlassCard>
);
}
3 changes: 1 addition & 2 deletions src/pages/Credits/Credits.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.container {
display: flex;
flex-direction: column;
gap: 2rem;
max-width: 1200px;
gap: 1rem;
margin: 0 auto;
text-align: center;
}
86 changes: 54 additions & 32 deletions src/pages/Credits/DependencyCreditsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import { useState, useEffect } from 'react';
import GlassCard from '@components/GlassCard';
import { useQueries } from '@tanstack/react-query';
import Tooltip from '@components/Tooltip';
import Pagination from '@components/Pagination';
import { ExternalLink } from 'lucide-react';
import styles from './DependencyCreditsCard.module.css';

const ONE_WEEK = 7 * 24 * 60 * 60 * 1000; // milliseconds
const PAGE_SIZE = 10;

export default function DependencyCreditsCard() {
const [deps, setDeps] = useState([]);
const [devDeps, setDevDeps] = useState([]);

const [depPage, setDepPage] = useState(0);
const [devDepPage, setDevDepPage] = useState(0);

useEffect(() => {
const url = 'https://raw.githubusercontent.com/Ryan-Millard/Img2Num/main/package.json';

Expand Down Expand Up @@ -36,47 +43,62 @@ export default function DependencyCreditsCard() {
const depQueries = useQueries({ queries: createQueries(deps) });
const devDepQueries = useQueries({ queries: createQueries(devDeps) });

const renderTable = (items, queries) => (
<table>
<tbody>
{items.map(([name, version], index) => {
const query = queries[index];
const data = query?.data;

return (
<tr key={`${name}-${index}`}>
<td>{name}</td>
<td>{version}</td>
<td>
{query?.isLoading ? (
'Loading...'
) : data?.url ? (
<Tooltip content={`Open ${name} homepage`}>
<a href={data.url} target="_blank" rel="noopener noreferrer">
{data.url}
</a>
</Tooltip>
) : (
'No URL'
)}
</td>
</tr>
);
})}
</tbody>
</table>
);
// pagination helper
const paginatedItems = (items, page) => items.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE);

const renderTable = (items, queries, page) => {
const visibleItems = paginatedItems(items, page);

return (
<table className={styles.table}>
<tbody>
{visibleItems.map(([name, version], localIndex) => {
const globalIndex = page * PAGE_SIZE + localIndex;
const query = queries[globalIndex];
const data = query?.data;

return (
<tr key={`${name}-${globalIndex}`}>
<td>{name}</td>
<td>{version}</td>
<td>
{query?.isLoading ? (
'Loading...'
) : data?.url ? (
<Tooltip content={`Open ${name} homepage`}>
<a href={data.url} target="_blank" rel="noopener noreferrer">
<span className={styles.fullUrl}>{data.url}</span>
<ExternalLink className={styles.iconUrl} size={18} />
</a>
</Tooltip>
) : (
'No URL'
)}
</td>
</tr>
);
})}
</tbody>
</table>
);
};

return (
<>
<GlassCard>
<h2>Dependencies</h2>
{renderTable(deps, depQueries)}

{renderTable(deps, depQueries, depPage)}

<Pagination page={depPage} totalPages={Math.ceil(deps.length / PAGE_SIZE)} onChange={setDepPage} />
</GlassCard>

<GlassCard>
<h2>Dev Dependencies</h2>
{renderTable(devDeps, devDepQueries)}

{renderTable(devDeps, devDepQueries, devDepPage)}

<Pagination page={devDepPage} totalPages={Math.ceil(devDeps.length / PAGE_SIZE)} onChange={setDevDepPage} />
</GlassCard>
</>
);
Expand Down
Loading
Loading