mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-12 22:15:27 -04:00
fix: console scroll to bottom on change + more logs + dont wrap
This commit is contained in:
@@ -2,13 +2,21 @@ import cx from '@src/cx.mjs';
|
||||
import { useSettings } from '../../../settings.mjs';
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { $strudel_log_history } from '../useLogger';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export function ConsoleTab() {
|
||||
const log = useStore($strudel_log_history);
|
||||
const { fontFamily } = useSettings();
|
||||
const scrollRef = useRef();
|
||||
// scroll to bottom when log changes
|
||||
useEffect(() => {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||
}
|
||||
}, [log]);
|
||||
return (
|
||||
<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 */}
|
||||
{log.map((l, i) => {
|
||||
@@ -18,12 +26,13 @@ export function ConsoleTab() {
|
||||
<div
|
||||
key={l.id}
|
||||
className={cx(
|
||||
'whitespace-nowrap',
|
||||
l.type === 'error' ? 'text-background bg-foreground' : 'text-foreground',
|
||||
l.type === 'highlight' && 'underline',
|
||||
)}
|
||||
style={color ? { color } : {}}
|
||||
>
|
||||
<span dangerouslySetInnerHTML={{ __html: message }} />
|
||||
<span dangerouslySetInnerHTML={{ __html: message }} className="whitespace-nowrap" />
|
||||
{l.count ? ` (${l.count})` : ''}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ function getUpdatedLog(log, event) {
|
||||
} else {
|
||||
log = log.concat([{ message, type, id, data }]);
|
||||
}
|
||||
return log.slice(-20);
|
||||
return log.slice(-40);
|
||||
}
|
||||
|
||||
export function useLogger() {
|
||||
|
||||
Reference in New Issue
Block a user