Skip to content

Commit 2d3bd3d

Browse files
committed
First version of new converter
1 parent ac9db05 commit 2d3bd3d

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/app/converter.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import { useState } from "react";
22

33
import AppFileSelect from "@/components/libresplit/AppFileSelect";
44
import init, { convert } from "@libresplit/libresplit-converter";
@@ -8,9 +8,8 @@ export function Converter() {
88
const [selectedFile, setSelectedFile] = useState<File | null>(null);
99
const [result, setResult] = useState<string | null>(null);
1010

11-
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
12-
const file = event.target.files?.[0] || null;
13-
setSelectedFile(file);
11+
const handleSelectChange = (files: File | File[] | null) => {
12+
setSelectedFile(Array.isArray(files) ? (files[0] ?? null) : files);
1413
};
1514

1615
const handleSubmit = async () => {
@@ -21,11 +20,8 @@ export function Converter() {
2120

2221
try {
2322
const text = await selectedFile.text();
24-
2523
await init(wasmUrl);
26-
2724
const converted = convert(text);
28-
2925
setResult(converted);
3026
} catch (error) {
3127
console.error("Error processing file: ", error);
@@ -37,21 +33,41 @@ export function Converter() {
3733
if (!result || !selectedFile) return;
3834

3935
const fileName = selectedFile.name.replace(/\.[^/.]+$/, ".json");
40-
4136
const blob = new Blob([result], { type: "application/json" });
4237
const url = URL.createObjectURL(blob);
4338

4439
const link = document.createElement("a");
4540
link.href = url;
4641
link.download = fileName;
4742
link.click();
48-
4943
URL.revokeObjectURL(url);
5044
};
5145

5246
return (
53-
<div>
54-
<AppFileSelect />
47+
<div className="space-y-4">
48+
<AppFileSelect
49+
label="Select LiveSplit file:"
50+
value={selectedFile}
51+
onChange={handleSelectChange}
52+
multiple={false}
53+
filters={[{ name: "LiveSplit (.lss)", extensions: ["lss", "xml"] }]}
54+
/>
55+
56+
<div className="flex gap-2">
57+
<button
58+
onClick={handleSubmit}
59+
className="rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700"
60+
>
61+
Convert
62+
</button>
63+
<button
64+
onClick={handleDownload}
65+
disabled={!result}
66+
className="rounded bg-gray-200 px-4 py-2 text-black disabled:opacity-50"
67+
>
68+
Download Splits
69+
</button>
70+
</div>
5571
</div>
5672
);
5773
}

0 commit comments

Comments
 (0)