diff options
Diffstat (limited to 'Omni/Jr/Web.hs')
| -rw-r--r-- | Omni/Jr/Web.hs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/Omni/Jr/Web.hs b/Omni/Jr/Web.hs index a493395..6a2d826 100644 --- a/Omni/Jr/Web.hs +++ b/Omni/Jr/Web.hs @@ -2273,11 +2273,23 @@ renderLiveToggle = ] " LIVE" --- | JavaScript for toggling live updates +-- | Render the autoscroll toggle button +renderAutoscrollToggle :: (Monad m) => Lucid.HtmlT m () +renderAutoscrollToggle = + Lucid.button_ + [ Lucid.class_ "timeline-autoscroll-toggle", + Lucid.id_ "autoscroll-toggle", + Lucid.makeAttribute "onclick" "toggleAutoscroll()", + Lucid.title_ "Toggle automatic scrolling to newest events" + ] + " ⬇ Auto-scroll" + +-- | JavaScript for toggling live updates and autoscroll liveToggleJs :: Text liveToggleJs = Text.unlines [ "var liveUpdatesEnabled = true;", + "var autoscrollEnabled = true;", "", "function toggleLiveUpdates() {", " liveUpdatesEnabled = !liveUpdatesEnabled;", @@ -2287,11 +2299,28 @@ liveToggleJs = " }", "}", "", + "function toggleAutoscroll() {", + " autoscrollEnabled = !autoscrollEnabled;", + " var btn = document.getElementById('autoscroll-toggle');", + " if (btn) {", + " btn.classList.toggle('timeline-autoscroll-disabled', !autoscrollEnabled);", + " }", + "}", + "", "document.body.addEventListener('htmx:beforeRequest', function(evt) {", " var timeline = document.getElementById('unified-timeline');", " if (timeline && timeline.contains(evt.target) && !liveUpdatesEnabled) {", " evt.preventDefault();", " }", + "});", + "", + "document.body.addEventListener('htmx:afterSettle', function(evt) {", + " if (autoscrollEnabled) {", + " var log = document.querySelector('.timeline-events');", + " if (log) {", + " log.scrollTop = log.scrollHeight;", + " }", + " }", "});" ] @@ -2352,7 +2381,9 @@ renderUnifiedTimeline tid legacyComments events status now = do when (totalCents > 0) <| Lucid.toHtml (formatCostHeader totalCents) when (totalCents > 0 && totalTokens > 0) <| metaSep when (totalTokens > 0) <| Lucid.toHtml (formatTokensHeader totalTokens <> " tokens") - when isInProgress <| renderLiveToggle + when isInProgress <| do + renderLiveToggle + renderAutoscrollToggle if null nonCostEvents && null legacyComments then Lucid.p_ [Lucid.class_ "empty-msg"] "No activity yet." |
