weiro/views/posts/index.html
Leon Mika d7a5d425b8 feat: add pagination controls to admin post list
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 14:34:55 +11:00

83 lines
3.6 KiB
HTML

{{ $showingTrash := eq .req.Filter "deleted" }}
<main class="container">
<div class="my-4 d-flex justify-content-between align-items-baseline">
<div>
<a href="/sites/{{ .site.ID }}/posts/new" class="btn btn-success">New Post</a>
</div>
<div>
<div class="btn-group" role="group" aria-label="First group">
{{ if $showingTrash }}
<a href="/sites/{{ .site.ID }}/posts" type="button" class="btn btn-secondary" title="Trash">🗑️</a>
{{ else }}
<a href="/sites/{{ .site.ID }}/posts?filter=deleted" type="button" class="btn btn-outline-secondary" title="Trash">🗑️</a>
{{ end }}
</div>
</div>
</div>
{{ range $i, $p := .posts }}
<div data-controller="postlist"
data-postlist-site-id-value="{{ $p.SiteID }}"
data-postlist-post-id-value="{{ $p.ID }}"
data-postlist-nano-summary-value="{{ $p.NanoSummary }}"
class="postlist">
<div class="my-4 post">
{{ if $p.Title }}<h4 class="mb-3">{{ $p.Title }}</h4>{{ end }}
{{ markdown $p.Body $.site }}
<div class="mb-3 d-flex align-items-center flex-wrap gap-1">
{{ if eq $p.State 1 }}
<span class="text-muted post-date">{{ $.user.FormatTime $p.UpdatedAt }}</span> <span class="ms-3 badge text-primary-emphasis bg-primary-subtle border border-primary-subtle">Draft</span>
{{ else }}
<span class="text-muted post-date">{{ $.user.FormatTime $p.PublishedAt }}</span>
{{ end }}
</div>
<div class="mb-3 d-flex align-items-center">
{{ if $showingTrash }}
<span>
<a href="#" data-action="click->postlist#restorePost" class="btn btn-outline-secondary btn-sm">Restore</a>
<a href="#" data-action="click->postlist#deletePost" data-postlist-hard-delete-param="true"
class="btn btn-outline-danger btn-sm">Delete</a>
</span>
{{ else }}
<span>
<a href="/sites/{{ $.site.ID }}/posts/{{ $p.ID }}/"
class="btn btn-outline-secondary btn-sm">Edit</a>
<a href="#" data-action="click->postlist#deletePost"
class="btn btn-outline-secondary btn-sm">Trash</a>
</span>
{{ end }}
</div>
</div>
{{ if lt $i (sub (len $.posts) 1) }}<hr>{{ end }}
</div>
{{ else }}
<div class="h4 m-3 text-center">
{{ if $showingTrash }}
<div class="position-absolute top-50 start-50 translate-middle">🗑️<br>Trash is empty.</div>
{{ else }}
<div class="position-absolute top-50 start-50 translate-middle">🌱<br>No posts yet. Better get writing!</div>
{{ end }}
</div>
{{ end }}
{{ if gt .pageInfo.TotalPages 1 }}
<nav aria-label="Page navigation" class="my-4">
<ul class="pagination justify-content-center">
<li class="page-item{{ if not .pageInfo.HasPrevious }} disabled{{ end }}">
<a class="page-link" href="?page={{ .pageInfo.PreviousPage }}{{ if .req.Filter }}&filter={{ .req.Filter }}{{ end }}">Previous</a>
</li>
{{ range $p := .pageInfo.Pages }}
<li class="page-item{{ if eq $p $.pageInfo.CurrentPage }} active{{ end }}">
<a class="page-link" href="?page={{ $p }}{{ if $.req.Filter }}&filter={{ $.req.Filter }}{{ end }}">{{ $p }}</a>
</li>
{{ end }}
<li class="page-item{{ if not .pageInfo.HasNext }} disabled{{ end }}">
<a class="page-link" href="?page={{ .pageInfo.NextPage }}{{ if .req.Filter }}&filter={{ .req.Filter }}{{ end }}">Next</a>
</li>
</ul>
</nav>
{{ end }}
</main>