feat: add open/closed state filter to PR list view
Mirror the existing issues state filter pattern: read state query param (default "open"), pass it to ListAllPullRequests instead of hardcoded "open", and add a state select widget to the pulls filter bar with proper hx-include for HTMX partial reloads and infinite scroll. Closes leeworks-agents/gitea-mobile#72 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -323,12 +323,17 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) {
|
|||||||
Pulls []giteaclient.PullRequest
|
Pulls []giteaclient.PullRequest
|
||||||
Orgs []string
|
Orgs []string
|
||||||
SelectedOrg string
|
SelectedOrg string
|
||||||
|
SelectedState string
|
||||||
HasMore bool
|
HasMore bool
|
||||||
NextPage int
|
NextPage int
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedOrg := r.URL.Query().Get("org")
|
selectedOrg := r.URL.Query().Get("org")
|
||||||
|
selectedState := r.URL.Query().Get("state")
|
||||||
|
if selectedState == "" {
|
||||||
|
selectedState = "open"
|
||||||
|
}
|
||||||
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
|
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
|
||||||
if page < 1 {
|
if page < 1 {
|
||||||
page = 1
|
page = 1
|
||||||
@@ -337,6 +342,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) {
|
|||||||
data := pullsData{
|
data := pullsData{
|
||||||
Orgs: orgNames,
|
Orgs: orgNames,
|
||||||
SelectedOrg: selectedOrg,
|
SelectedOrg: selectedOrg,
|
||||||
|
SelectedState: selectedState,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(orgNames) == 0 {
|
if len(orgNames) == 0 {
|
||||||
@@ -347,7 +353,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) {
|
|||||||
queryOrgs = []string{selectedOrg}
|
queryOrgs = []string{selectedOrg}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs, "open", page)
|
result, err := h.Client.ListAllPullRequests(r.Context(), token, queryOrgs, selectedState, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to list pull requests", "error", err)
|
slog.Error("failed to list pull requests", "error", err)
|
||||||
data.Error = "Error loading pull requests."
|
data.Error = "Error loading pull requests."
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .HasMore}}
|
{{if .HasMore}}
|
||||||
<div class="scroll-sentinel" hx-get="/pulls?page={{.NextPage}}&org={{.SelectedOrg}}" hx-trigger="revealed" hx-swap="outerHTML" hx-target="this">
|
<div class="scroll-sentinel" hx-get="/pulls?page={{.NextPage}}&org={{.SelectedOrg}}&state={{.SelectedState}}" hx-trigger="revealed" hx-swap="outerHTML" hx-target="this">
|
||||||
<div class="spinner htmx-indicator"></div>
|
<div class="spinner htmx-indicator"></div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
@@ -27,18 +27,22 @@
|
|||||||
<h1>Pull Requests</h1>
|
<h1>Pull Requests</h1>
|
||||||
|
|
||||||
<div class="filter-bar">
|
<div class="filter-bar">
|
||||||
<select name="org" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true">
|
<select name="org" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='state']">
|
||||||
<option value="">All orgs</option>
|
<option value="">All orgs</option>
|
||||||
{{range .Orgs}}
|
{{range .Orgs}}
|
||||||
<option value="{{.}}" {{if eq . $.SelectedOrg}}selected{{end}}>{{.}}</option>
|
<option value="{{.}}" {{if eq . $.SelectedOrg}}selected{{end}}>{{.}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
|
<select name="state" hx-get="/pulls" hx-trigger="change" hx-target="#main-content" hx-swap="innerHTML" hx-push-url="true" hx-include="[name='org']">
|
||||||
|
<option value="open" {{if eq .SelectedState "open"}}selected{{end}}>Open</option>
|
||||||
|
<option value="closed" {{if eq .SelectedState "closed"}}selected{{end}}>Closed</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if .Error}}
|
{{if .Error}}
|
||||||
<p class="empty">{{.Error}}</p>
|
<p class="empty">{{.Error}}</p>
|
||||||
{{else if not .Pulls}}
|
{{else if not .Pulls}}
|
||||||
<p class="empty">No open pull requests found.</p>
|
<p class="empty">No {{.SelectedState}} pull requests found.</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div id="pull-list">
|
<div id="pull-list">
|
||||||
{{template "cards" .}}
|
{{template "cards" .}}
|
||||||
|
|||||||
Reference in New Issue
Block a user