diff --git a/web/src/components/CodeBlock.tsx b/web/src/components/CodeBlock.tsx index 24967cb..3752992 100644 --- a/web/src/components/CodeBlock.tsx +++ b/web/src/components/CodeBlock.tsx @@ -13,10 +13,7 @@ export async function CodeBlock(props: { return (
- {/* max-w-[calc(32rem-1.5rem-1.5rem)] */} - {/*
*/}

- {/*

*/}
); diff --git a/web/src/components/CodeBlockClient.tsx b/web/src/components/CodeBlockClient.tsx new file mode 100644 index 0000000..1b3b0e9 --- /dev/null +++ b/web/src/components/CodeBlockClient.tsx @@ -0,0 +1,35 @@ +"use client"; + +import { CopyButton } from "@/components/CopyButton"; +import type { StringLiteralUnion } from "shikiji"; +import useSWR from "swr"; +import { highlight } from "../server/highlight"; + +export function CodeBlockClient({ + code, + lang, +}: { + code: string; + lang: StringLiteralUnion; +}) { + const { data } = useSWR(code, async () => { + return highlight(code.trim(), lang); + }); + + return ( +
+ {data && ( +

+ )} + +

+ ); +} diff --git a/web/src/components/LogsViewer.tsx b/web/src/components/LogsViewer.tsx index 0be4691..5b94ce0 100644 --- a/web/src/components/LogsViewer.tsx +++ b/web/src/components/LogsViewer.tsx @@ -14,10 +14,18 @@ export function LogsViewer({ logs, hideTimestamp, className, -}: { logs: LogsType; hideTimestamp?: boolean; className?: string }) { + stickToBottom = true, +}: { + logs: LogsType; + hideTimestamp?: boolean; + className?: string; + stickToBottom?: boolean; +}) { const container = useRef(null); useEffect(() => { + if (!stickToBottom) return; + // console.log(logs.length, container.current); if (container.current) { const scrollHeight = container.current.scrollHeight; @@ -27,11 +35,12 @@ export function LogsViewer({ behavior: "smooth", }); } - }, [logs.length]); + }, [logs.length, stickToBottom]); return (
{ + if (!stickToBottom) return; if (!container.current && ref) { const scrollHeight = ref.scrollHeight; diff --git a/web/src/components/OutputRender.tsx b/web/src/components/OutputRender.tsx index d42046e..2953f94 100644 --- a/web/src/components/OutputRender.tsx +++ b/web/src/components/OutputRender.tsx @@ -1,15 +1,25 @@ +"use client"; + +import useSWR from "swr"; import { DownloadButton } from "./DownloadButton"; import { getFileDownloadUrl } from "@/server/getFileDownloadUrl"; -export async function OutputRender(props: { +export function OutputRender(props: { run_id: string; filename: string; }) { - if (props.filename.endsWith(".mp4") || props.filename.endsWith(".webm")) { - const url = await getFileDownloadUrl( - `outputs/runs/${props.run_id}/${props.filename}`, - ); + const { data: url } = useSWR( + "run-outputs+" + props.run_id + props.filename, + async () => { + return await getFileDownloadUrl( + `outputs/runs/${props.run_id}/${props.filename}`, + ); + }, + ); + if (!url) return <>; + + if (props.filename.endsWith(".mp4") || props.filename.endsWith(".webm")) { return (
diff --git a/web/src/server/getRunsOutput.tsx b/web/src/server/getRunsOutput.tsx index 785a580..44bbae4 100644 --- a/web/src/server/getRunsOutput.tsx +++ b/web/src/server/getRunsOutput.tsx @@ -1,16 +1,10 @@ "use server"; -import { RunOutputs } from "@/components/RunOutputs"; import { db } from "@/db/db"; import { workflowRunOutputs } from "@/db/schema"; import { eq } from "drizzle-orm"; -// export async function getRunsOutputDisplay(run_id: string) { -// return ; -// } - export async function getRunsOutput(run_id: string) { - // throw new Error("Not implemented"); return await db .select() .from(workflowRunOutputs) diff --git a/web/src/server/highlight.tsx b/web/src/server/highlight.tsx new file mode 100644 index 0000000..c4b4cd5 --- /dev/null +++ b/web/src/server/highlight.tsx @@ -0,0 +1,18 @@ +"use server"; + +import type { StringLiteralUnion } from "shikiji"; +import { getHighlighter } from "shikiji"; + +export async function highlight( + code: string, + lang: StringLiteralUnion, +) { + const highlighter = await getHighlighter({ + themes: ["one-dark-pro"], + langs: [lang], + }); + return highlighter.codeToHtml(code.trim(), { + lang: lang, + theme: "one-dark-pro", + }); +}