Skip to content

Commit

Permalink
Merge pull request #36 from pioneers/console
Browse files Browse the repository at this point in the history
Add autoscroll feature on AppConsole.tsx
  • Loading branch information
snowNnik authored Dec 1, 2024
2 parents 4c80b70 + 8adb5e7 commit 32dd84e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
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
12 changes: 11 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,18 @@ export default function AppConsole({
height: number;
messages: AppConsoleMessage[];
}) {
// Add autoscroll feature to AppConsole by setting the current scrollTop prop to the current scrollHeight value
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 32dd84e

Please sign in to comment.