diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-02-15 20:42:04 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-02-15 20:42:04 +0100 |
| commit | d1dcd0b49010bba31e44859e0d1d76abb7fb20fc (patch) | |
| tree | 9b0ef2f20679d708933de9876855b458249f1a08 /src/main.ts | |
| download | alahelo-madio-d1dcd0b49010bba31e44859e0d1d76abb7fb20fc.tar.gz alahelo-madio-d1dcd0b49010bba31e44859e0d1d76abb7fb20fc.tar.zst alahelo-madio-d1dcd0b49010bba31e44859e0d1d76abb7fb20fc.zip | |
Initial commit - v1.0.0
Diffstat (limited to 'src/main.ts')
| -rw-r--r-- | src/main.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..7ecd320 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,37 @@ +import './style.css' + +const URL = "http://localhost:8000/index.php"; + +(async () => { + const voivs = await (await fetch(URL)).json() as string[] + const tbody = document.getElementById('tds-here') as HTMLTableSectionElement; + for (let i = 0; i < voivs.length; i += 2) { + const tr = document.createElement("tr") + const td = document.createElement("td") + td.innerText = voivs[i + 1] + td.onclick = () => showCities(voivs[i + 1], voivs[i]); + tr.appendChild(td) + tbody.appendChild(tr) + } +})() + +async function showCities(n: string, id: string) { + const res = await (await fetch(URL, { + method: "POST", + body: id, + })).json() as string[] + // console.log(res) + const nh = document.getElementById("name-here") as HTMLTableRowElement + const vt = document.getElementById("vtds-here") as HTMLTableSectionElement + vt.innerHTML = '' + nh.innerHTML = `<th>Miasta w ${n} (${res.length}, <a href="https://duckduckgo.com/?q=wikipedia+Kategoria%3AMiasta+w+wojew%C3%B3dztwie+${n}" target="_blank">internet</a>)</th>` + + for (const c of res) { + const tr = document.createElement("tr") + const td = document.createElement("td") + td.innerText = c + tr.appendChild(td) + vt.appendChild(tr) + } +} + |
