Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Displays buttons for commit navigation

AuthorDave Jarvis <email>
Date2026-02-20 19:08:41 GMT-0800
Commit399282f4f70f81819030ed2a0852d3f7cd983cf1
Parent0b2254d
pages/CommitsPage.php
$current = $nav['current'];
$hasNext = $nav['hasNext'];
+ $hasAll = $nav['hasAll'];
$hasPrev = $current > 1;
- $prevSha = '';
- $prevUrl = '';
- $nextSha = '';
- $nextUrl = '';
+ $total = count( $pages );
if( $hasPrev || $hasNext ) {
echo '<div class="pagination">';
+ // First page button
if( $hasPrev ) {
- $prevSha = $pages[$current - 2];
- $prevUrl = $this->buildPageUrl( $prevSha );
+ $firstUrl = $this->buildPageUrl( $pages[0] );
+ echo '<a href="' . $firstUrl . '" class="page-link page-nav" aria-label="first">' .
+ $this->svgArrow( 'first' ) . '</a>';
+ } else {
+ echo '<span class="page-link page-nav page-nav-hidden" aria-hidden="true">' .
+ $this->svgArrow( 'first' ) . '</span>';
+ }
- echo '<a href="' . $prevUrl . '" class="page-link page-nav">&#8249; Back</a>';
+ // Back button
+ if( $hasPrev ) {
+ $prevUrl = $this->buildPageUrl( $pages[$current - 2] );
+ echo '<a href="' . $prevUrl . '" class="page-link page-nav" aria-label="back">' .
+ $this->svgArrow( 'back' ) . '</a>';
} else {
- echo '<span class="page-link page-nav page-nav-hidden">&#8249; Back</span>';
+ echo '<span class="page-link page-nav page-nav-hidden" aria-hidden="true">' .
+ $this->svgArrow( 'back' ) . '</span>';
}
$this->renderPageNumbers( $pages, $current );
+ // Next button
if( $hasNext ) {
- $nextSha = $pages[$current];
- $nextUrl = $this->buildPageUrl( $nextSha );
+ $nextUrl = $this->buildPageUrl( $pages[$current] );
+ echo '<a href="' . $nextUrl . '" class="page-link page-nav" aria-label="next">' .
+ $this->svgArrow( 'next' ) . '</a>';
+ } else {
+ echo '<span class="page-link page-nav page-nav-hidden" aria-hidden="true">' .
+ $this->svgArrow( 'next' ) . '</span>';
+ }
- echo '<a href="' . $nextUrl . '" class="page-link page-nav">Next &#8250;</a>';
+ // Last page button
+ if( $hasAll && $hasNext ) {
+ $lastUrl = $this->buildPageUrl( $pages[$total - 1] );
+ echo '<a href="' . $lastUrl . '" class="page-link page-nav" aria-label="last">' .
+ $this->svgArrow( 'last' ) . '</a>';
} else {
- echo '<span class="page-link page-nav page-nav-hidden">Next &#8250;</span>';
+ echo '<span class="page-link page-nav page-nav-hidden" aria-hidden="true">' .
+ $this->svgArrow( 'last' ) . '</span>';
}
echo '</div>';
}
+ }
+
+ private function svgArrow( string $type ): string {
+ $icons = [
+ 'back' => '<path d="M2 12 L7 17 V14 H9 V10 H7 V7 Z" />',
+ 'next' => '<path d="M22 12 L17 7 V10 H15 V14 H17 V17 Z" />',
+ 'first' => '<path d="M2 12 L7 17 V14 H9 V10 H7 V7 Z" />' .
+ '<path d="M9 12 L14 17 V14 H16 V10 H14 V7 Z" />',
+ 'last' => '<path d="M15 12 L10 7 V10 H8 V14 H10 V17 Z" />' .
+ '<path d="M22 12 L17 7 V10 H15 V14 H17 V17 Z" />',
+ ];
+
+ $inner = $icons[$type] ?? '';
+
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" ' .
+ 'viewBox="0 0 24 24" fill="#8b949e" aria-label="' . $type . '" role="img">' .
+ '<title>' . $type . '</title>' . $inner . '</svg>';
}
$currentPage = 1;
$found = false;
+ $hitLimit = false;
$result = [];
&$commits,
&$currentPage,
- &$found
+ &$found,
+ &$hitLimit
) {
$continue = true;
if( $found && count( $pageHashes ) > $currentPage + 10 ) {
+ $hitLimit = true;
$continue = false;
}
$result['pages'] = $pageHashes;
$result['current'] = $currentPage;
+ $result['hasAll'] = !$hitLimit;
$result['hasNext'] = $count === self::PER_PAGE &&
isset( $pageHashes[$currentPage] );
styles/repo.css
.page-nav {
- min-width: calc(6ch + 16px);
+ min-width: calc(20px + 16px);
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
}
Delta58 lines added, 14 lines removed, 44-line increase