blob: 95ca17f9dcf9467e71373484f9551b7c7fef83f7 [file] [log] [blame]
swissChiliab615d82024-03-08 17:15:13 -05001const React = require("preact");
2const {useState} = require('preact/hooks');
3
4export const UnitsApp = () => {
5 const [hist, setHist] = useState([]);
6 const [query, setQuery] = useState("");
7 const [to, setTo] = useState("");
8
9 function doConversion(e) {
10 e.preventDefault();
11 console.log("conversion");
12 setQuery('');
13 setTo('');
14
15 convert(query, to).then(res => {
swissChili16de3222024-03-08 17:55:11 -050016 setHist([...hist, [query, to, res]]);
swissChiliab615d82024-03-08 17:15:13 -050017 })
18 }
19
20 return (
swissChili16de3222024-03-08 17:55:11 -050021 <>
swissChiliab615d82024-03-08 17:15:13 -050022 <form class="query-row" onSubmit={doConversion}>
23 <input
24 type="text"
25 id="query"
26 value={query}
27 placeholder="From"
28 onChange={(val) => setQuery(val.target.value)}
29 ></input>
30 <input
31 type="text"
32 id="to"
33 value={to}
34 placeholder="To"
35 onChange={(val) => setTo(val.target.value)}
36 ></input>
37
swissChili16de3222024-03-08 17:55:11 -050038 <input value="Convert" type="submit"></input>
swissChiliab615d82024-03-08 17:15:13 -050039 </form>
40
swissChili16de3222024-03-08 17:55:11 -050041 <div class="table-container">
42 <table>
43 <thead>
44 <tr><td style="width: 30%">From</td><td style="width: 15%">To</td><td style="width: 55%">Result</td></tr>
45 </thead>
swissChiliab615d82024-03-08 17:15:13 -050046 {hist.map((entry) => (
swissChili16de3222024-03-08 17:55:11 -050047 <tr>{entry.map(t => <td>{t}</td>)}</tr>
swissChiliab615d82024-03-08 17:15:13 -050048 ))}
swissChili16de3222024-03-08 17:55:11 -050049 <tr><td></td></tr>
50 </table>
51 </div>
52 </>
swissChiliab615d82024-03-08 17:15:13 -050053 );
54};