Skip to content

Commit

Permalink
Add autoscroll feature on AppConsole.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
zh3nl committed Nov 30, 2024
1 parent 4c80b70 commit 4706b76
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Binary file added code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
"collective": {
"url": "https://opencollective.com/electron-react-boilerplate-594"
},
"devEngines": {
"engines": {
"node": ">=14.x",
"npm": ">=7.x"
},
Expand Down
1 change: 1 addition & 0 deletions src/renderer/AppConsole.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
margin: 0;
margin-bottom: 50px;
min-height: 0;
scroll-behavior: smooth;
}
.AppConsole-message {
padding: 2px;
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/AppConsole.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRef, useEffect } from 'react';
import AppConsoleMessage from '../common/AppConsoleMessage';
import './AppConsole.css';

Expand All @@ -14,9 +15,17 @@ export default function AppConsole({
height: number;
messages: AppConsoleMessage[];
}) {
const consoleRef = useRef<HTMLPreElement>(null);

useEffect(() => {
if (consoleRef.current) {
consoleRef.current.scrollTop = consoleRef.current.scrollHeight;
}
}, [messages]);

return (
<div className="AppConsole" style={{ height }}>
<pre className="AppConsole-inner">
<pre ref={consoleRef} className="AppConsole-inner">
{messages.map((msg: AppConsoleMessage) => (
<div
key={msg.uuid}
Expand Down

0 comments on commit 4706b76

Please sign in to comment.