fix: console scroll to bottom on change + more logs + dont wrap
This commit is contained in:
parent
8e5ca57edd
commit
4993ec4cbf
2 changed files with 12 additions and 3 deletions
|
|
@ -2,13 +2,21 @@ import cx from '@src/cx.mjs';
|
||||||
import { useSettings } from '../../../settings.mjs';
|
import { useSettings } from '../../../settings.mjs';
|
||||||
import { useStore } from '@nanostores/react';
|
import { useStore } from '@nanostores/react';
|
||||||
import { $strudel_log_history } from '../useLogger';
|
import { $strudel_log_history } from '../useLogger';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
export function ConsoleTab() {
|
export function ConsoleTab() {
|
||||||
const log = useStore($strudel_log_history);
|
const log = useStore($strudel_log_history);
|
||||||
const { fontFamily } = useSettings();
|
const { fontFamily } = useSettings();
|
||||||
|
const scrollRef = useRef();
|
||||||
|
// scroll to bottom when log changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (scrollRef.current) {
|
||||||
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||||
|
}
|
||||||
|
}, [log]);
|
||||||
return (
|
return (
|
||||||
<div id="console-tab" className="break-all w-full h-full" style={{ fontFamily }}>
|
<div id="console-tab" className="break-all w-full h-full" style={{ fontFamily }}>
|
||||||
<div className="h-full w-full overflow-auto space-y-1 p-2 rounded-md">
|
<div className="h-full w-full overflow-auto space-y-1 p-2 rounded-md" ref={scrollRef}>
|
||||||
{' '}
|
{' '}
|
||||||
{/* bg-background */}
|
{/* bg-background */}
|
||||||
{log.map((l, i) => {
|
{log.map((l, i) => {
|
||||||
|
|
@ -18,12 +26,13 @@ export function ConsoleTab() {
|
||||||
<div
|
<div
|
||||||
key={l.id}
|
key={l.id}
|
||||||
className={cx(
|
className={cx(
|
||||||
|
'whitespace-nowrap',
|
||||||
l.type === 'error' ? 'text-background bg-foreground' : 'text-foreground',
|
l.type === 'error' ? 'text-background bg-foreground' : 'text-foreground',
|
||||||
l.type === 'highlight' && 'underline',
|
l.type === 'highlight' && 'underline',
|
||||||
)}
|
)}
|
||||||
style={color ? { color } : {}}
|
style={color ? { color } : {}}
|
||||||
>
|
>
|
||||||
<span dangerouslySetInnerHTML={{ __html: message }} />
|
<span dangerouslySetInnerHTML={{ __html: message }} className="whitespace-nowrap" />
|
||||||
{l.count ? ` (${l.count})` : ''}
|
{l.count ? ` (${l.count})` : ''}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ function getUpdatedLog(log, event) {
|
||||||
} else {
|
} else {
|
||||||
log = log.concat([{ message, type, id, data }]);
|
log = log.concat([{ message, type, id, data }]);
|
||||||
}
|
}
|
||||||
return log.slice(-20);
|
return log.slice(-40);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useLogger() {
|
export function useLogger() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue