Skip to content

Commit

Permalink
Add LogScrollHook for auto-scrolling log area
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondFrank committed Dec 5, 2024
1 parent 029ca56 commit a8e0ac3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/js/hooks/editor-form-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const EditorFormHook = {
let new_state = view.state.update({
changes: { from: 0, to: view.state.doc.length, insert: event.detail.content }
});
view.dispatch(new_state)
view.dispatch(new_state);
});
}
};
Expand Down
3 changes: 3 additions & 0 deletions assets/js/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import LogScrollHook from "./log-scroll-hook";
import EditorFormHook from "./editor-form-hook";


export default {
LogScrollHook,
EditorFormHook
};
16 changes: 16 additions & 0 deletions assets/js/hooks/log-scroll-hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const LogScrollHook = {
mounted() {
this.scheduleScroll();
},
updated() {
this.scheduleScroll();
},
scheduleScroll() {
// Schedule the scroll to happen after the next frame to ensure the DOM is updated
requestAnimationFrame(() => {
this.el.scrollTop = this.el.scrollHeight;
});
}
};

export default LogScrollHook;
2 changes: 1 addition & 1 deletion lib/compass_admin_web/components/deployment_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule CompassAdminWeb.Components.DeploymentPage do
<div class="grid grid-cols-3 gap-4">
<div class="col-span-2 bg-white shadow-md rounded-lg p-4 max-h-screen">
<h2 class="text-xl pb-2"><%= @title %></h2>
<div class="overflow-auto h-4/5">
<div class="overflow-auto h-4/5" phx-hook="LogScrollHook" id="log-scroll-hook">
<ul>
<%= for log <- Enum.reverse(@agent_state.logs) do %>
<li class="text-nowrap text-gray-400 pb-1 pt-1"><%= log %></li>
Expand Down

0 comments on commit a8e0ac3

Please sign in to comment.