From d1dcd0b49010bba31e44859e0d1d76abb7fb20fc Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 15 Feb 2022 20:42:04 +0100 Subject: Initial commit - v1.0.0 --- src/main.ts | 37 +++++++++++++++++++++++++++++++++++++ src/style.css | 11 +++++++++++ src/vite-env.d.ts | 1 + 3 files changed, 49 insertions(+) create mode 100644 src/main.ts create mode 100644 src/style.css create mode 100644 src/vite-env.d.ts (limited to 'src') 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 = `Miasta w ${n} (${res.length}, internet)` + + for (const c of res) { + const tr = document.createElement("tr") + const td = document.createElement("td") + td.innerText = c + tr.appendChild(td) + vt.appendChild(tr) + } +} + diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..cc62277 --- /dev/null +++ b/src/style.css @@ -0,0 +1,11 @@ +html { + font-family: Avenir, Helvetica, Arial, sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + text-align: center; + color: #2c3e50; + margin-top: 60px; +} +td, th { + border: 1px solid black; +} diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1 @@ +/// -- cgit v1.3.1