Skip to content

Commit 1ffd7bc

Browse files
committed
fix(web): auto-close popups after commit/cancel actions
Commit bar stayed visible showing "0 pending changes" after a successful commit because the oob_save_ok template always included the visible class. Now conditional on ChangeCount > 0. Tool overlay confirm prompt stayed in the DOM after clicking Confirm because only close/cancel had removal handlers. Added afterRequest handler to remove the confirm overlay when the form completes. Commit with conflicts returned a full page layout for HTMX requests, breaking the diff modal. Now returns the modal fragment with the conflict message so the user can see the error and cancel.
1 parent 94b2bea commit 1ffd7bc

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

internal/component/web/assets/cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@
582582
if (overlay) overlay.remove();
583583
}
584584
});
585+
document.addEventListener('htmx:afterRequest', function(e) {
586+
if (e.target && e.target.classList &&
587+
e.target.classList.contains('tool-overlay-confirm-form')) {
588+
var overlay = e.target.closest('.tool-overlay');
589+
if (overlay) overlay.remove();
590+
}
591+
});
585592
}
586593

587594
// CLI page: SSH-style terminal with output viewport, message area, and input.

internal/component/web/handler_config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,22 @@ func handleCommitPost(w http.ResponseWriter, r *http.Request, mgr *EditorManager
832832
fmt.Fprintf(&msg, " %s: want %q, other (%s) has %q\n", c.Path, c.MyValue, c.OtherUser, c.OtherValue)
833833
}
834834

835+
if r.Header.Get("HX-Request") == htmxRequestTrue {
836+
type diffData struct {
837+
Diff string
838+
ChangeCount int
839+
}
840+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
841+
modal := renderer.RenderFragment("diff_modal_open", diffData{
842+
Diff: msg.String(),
843+
ChangeCount: mgr.ChangeCount(username),
844+
})
845+
if _, writeErr := w.Write([]byte(modal)); writeErr != nil {
846+
return
847+
}
848+
return
849+
}
850+
835851
layoutData := LayoutData{
836852
Title: "Commit Conflicts",
837853
NotificationHTML: template.HTML("<pre>" + template.HTMLEscapeString(msg.String()) + "</pre>"), //nolint:gosec // escaped

internal/component/web/templates/component/oob_save.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{define "oob_save_ok"}}
2-
<div id="commit-bar" class="commit-bar visible" hx-swap-oob="outerHTML">
2+
<div id="commit-bar" class="commit-bar{{if gt .ChangeCount 0}} visible{{end}}" hx-swap-oob="outerHTML">
33
<span id="commit-count" class="commit-count">{{.ChangeCount}} pending change{{if ne .ChangeCount 1}}s{{end}}</span>
44
<button class="commit-btn" id="commit-review-btn" hx-get="/config/diff" hx-target="#diff-modal" hx-swap="outerHTML">Review &amp; Commit</button>
55
<button class="commit-discard-btn" id="commit-discard-btn" hx-post="/config/discard" hx-swap="none">Discard</button>

0 commit comments

Comments
 (0)