Prettify CSV display

This commit is contained in:
Guntis Smaukstelis
2023-05-21 00:22:08 +03:00
parent 5744f5c214
commit 040672d6e0
2 changed files with 29 additions and 8 deletions
+3 -8
View File
@@ -1,5 +1,6 @@
import { Accessor, Component, createResource, JSXElement } from "solid-js";
import { apiHost } from "../consts";
import { PrettifyCSV } from "./PrettifyCSV";
export const FileContent: Component<{getFileName: Accessor<string>}> = (props) => {
const fetchFileContent = async (fileName: string) => {
@@ -11,6 +12,7 @@ export const FileContent: Component<{getFileName: Accessor<string>}> = (props) =
}
const [contentResource] = createResource(props.getFileName, fetchFileContent);
const lines = () => contentResource()?.split("<br/>") ?? ["empty..."];
return (
<div>
@@ -24,15 +26,8 @@ export const FileContent: Component<{getFileName: Accessor<string>}> = (props) =
<div>Error while loading file content: ${contentResource.error}</div>
)}
{ contentResource() && (
<div>{splitLines(contentResource())}</div>
<PrettifyCSV lines={lines} />
)}
</div>
)
}
function splitLines(str?: string): JSXElement {
const lines = str?.split("<br/>") ?? ["empty..."]
return lines.map(line =>
<div>{line}</div>
);
}