diff --git a/client/.gitignore b/client/.gitignore index a547bf36..019e1dca 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -1,5 +1,4 @@ # Logs -logs *.log npm-debug.log* yarn-debug.log* diff --git a/client/src/components/Logs/Logs.module.sass b/client/src/components/Logs/Logs.module.sass new file mode 100644 index 00000000..20adf4c4 --- /dev/null +++ b/client/src/components/Logs/Logs.module.sass @@ -0,0 +1,27 @@ +@use "../../styles/colors" +@use "../../styles/dimensions" +@use "../../styles/fonts" + +.logs + line-height: 2 + font-size: 13px + font-family: fonts.$font-family-code + border: 1px solid colors.$bg-tertiary + padding: 10px + border-radius: dimensions.$border-radius-lg + overflow: scroll + white-space: break-spaces + +.line + display: flex + flex-direction: row + gap: 10px + padding: 0 10px + border-radius: 4px + + &Error + color: colors.$red + +.number + color: colors.$fg-primary + opacity: 0.4 diff --git a/client/src/components/Logs/Logs.tsx b/client/src/components/Logs/Logs.tsx new file mode 100644 index 00000000..dabd81e8 --- /dev/null +++ b/client/src/components/Logs/Logs.tsx @@ -0,0 +1,66 @@ +import { HTMLProps, useEffect, useRef, useState } from "react"; + +import styles from "./Logs.module.sass"; +import classNames from "classnames"; +import useScrollPercentage from "react-scroll-percentage-hook"; +import Downloads from "../Downloads/Downloads"; + +export type LogLine = { + kind: "out" | "err" | "downloads"; + message: any; +}; + +function Line(props: LogLine) { + const { kind, message } = props; + + if (kind === "downloads") { + return ; + } + + if (message.value === undefined) return null; + if (message.value === "") return null; + + return ( +
+
{message.value}
+
+ ); +} + +type Props = HTMLProps & { + lines: LogLine[]; +}; + +export default function Logs(props: Readonly) { + const { lines } = props; + + const { ref } = useScrollPercentage({ + onProgress: (percentage) => { + setAutoScroll(percentage.vertical === 100); + }, + }); + + const [autoScroll, setAutoScroll] = useState(true); + + const scroll = useRef(); + + useEffect(() => { + if (!autoScroll) return; + let s: any = scroll; + s.current.scrollIntoView({ behavior: "smooth" }); + }, [autoScroll, lines]); + + return ( +
+ {lines.map((line, i) => { + return ; + })} +
+
+ ); +}