Skip to content

Commit dcbbbdb

Browse files
committed
Show before and after previews
1 parent 2d2bf35 commit dcbbbdb

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/app/converter.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ import wasmUrl from "@libresplit/libresplit-converter/libresplit_converter_bg.wa
77

88
export function Converter() {
99
const [selectedFile, setSelectedFile] = useState<File | null>(null);
10+
const [fileText, setFileText] = useState<string | null>(null);
1011
const [result, setResult] = useState<string | null>(null);
1112

12-
const handleSelectChange = (files: File | File[] | null) => {
13-
setSelectedFile(Array.isArray(files) ? (files[0] ?? null) : files);
13+
const handleSelectChange = async (files: File | File[] | null) => {
14+
const file = Array.isArray(files) ? (files[0] ?? null) : files;
15+
setSelectedFile(file);
16+
setResult(null);
17+
setFileText(null);
18+
19+
if (file) {
20+
const text = await file.text();
21+
setFileText(text);
22+
}
1423
};
1524

1625
const handleSubmit = async () => {
@@ -72,11 +81,10 @@ export function Converter() {
7281
</button>
7382
</div>
7483

75-
{result && (
76-
<div className="flex items-center justify-center">
77-
<AppMarkdownCodeBlock code={result} language="json" />
78-
</div>
79-
)}
84+
<div className="flex justify-center">
85+
{fileText && <AppMarkdownCodeBlock code={fileText} language="xml" />}
86+
{result && <AppMarkdownCodeBlock code={result} language="json" />}
87+
</div>
8088
</div>
8189
);
8290
}

0 commit comments

Comments
 (0)