swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 1 | const React = require("preact"); |
| 2 | const {useState} = require('preact/hooks'); |
| 3 | |
| 4 | export 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 => { |
swissChili | 16de322 | 2024-03-08 17:55:11 -0500 | [diff] [blame^] | 16 | setHist([...hist, [query, to, res]]); |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 17 | }) |
| 18 | } |
| 19 | |
| 20 | return ( |
swissChili | 16de322 | 2024-03-08 17:55:11 -0500 | [diff] [blame^] | 21 | <> |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 22 | <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 | |
swissChili | 16de322 | 2024-03-08 17:55:11 -0500 | [diff] [blame^] | 38 | <input value="Convert" type="submit"></input> |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 39 | </form> |
| 40 | |
swissChili | 16de322 | 2024-03-08 17:55:11 -0500 | [diff] [blame^] | 41 | <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> |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 46 | {hist.map((entry) => ( |
swissChili | 16de322 | 2024-03-08 17:55:11 -0500 | [diff] [blame^] | 47 | <tr>{entry.map(t => <td>{t}</td>)}</tr> |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 48 | ))} |
swissChili | 16de322 | 2024-03-08 17:55:11 -0500 | [diff] [blame^] | 49 | <tr><td></td></tr> |
| 50 | </table> |
| 51 | </div> |
| 52 | </> |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 53 | ); |
| 54 | }; |