This commit is contained in:
2026-08-31 20:16:08 +02:00
parent fa79880771
commit eb8ff84739
10 changed files with 389 additions and 582 deletions
+28
View File
@@ -0,0 +1,28 @@
const form = document.querySelector('#review-form');
const statusBox = document.querySelector('#status');
const resultBox = document.querySelector('#result');
const button = form.querySelector('button');
form.addEventListener('submit', async (event) => {
event.preventDefault(); button.disabled = true; resultBox.hidden = true;
statusBox.className = 'status'; statusBox.textContent = 'Odczytuję dokładne liczniki…';
try {
const response = await fetch('/api/reviews', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({url: document.querySelector('#maps-url').value})});
const data = await response.json();
if (!response.ok) throw new Error(data.error || 'Nie udało się pobrać danych.');
document.querySelector('#total').textContent = data.total.toLocaleString('pl-PL');
document.querySelector('#average').textContent = data.average.toLocaleString('pl-PL', {minimumFractionDigits: 2});
const max = Math.max(...Object.values(data.ratings), 1);
const rows = Object.entries(data.ratings).map(([stars, count]) => {
const row = document.createElement('div'); row.className = 'rating-row';
const label = document.createElement('span'); label.textContent = `${stars}`;
const bar = document.createElement('div'); bar.className = 'bar';
const fill = document.createElement('i'); fill.style.width = `${count / max * 100}%`; bar.append(fill);
const value = document.createElement('strong'); value.textContent = count.toLocaleString('pl-PL');
row.append(label, bar, value); return row;
});
document.querySelector('#ratings').replaceChildren(...rows);
statusBox.textContent = ''; resultBox.hidden = false;
} catch (error) { statusBox.className = 'status error'; statusBox.textContent = error.message; }
finally { button.disabled = false; }
});
+18
View File
@@ -0,0 +1,18 @@
:root { font-family: Inter, ui-sans-serif, system-ui, sans-serif; color: #202124; background: #f3f5f7; }
* { box-sizing: border-box; } body { margin: 0; min-height: 100vh; }
main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.card { width: min(680px, 100%); padding: clamp(24px, 6vw, 52px); background: #fff; border: 1px solid #e2e6ea; border-radius: 24px; box-shadow: 0 18px 55px #1f293714; }
.eyebrow { margin: 0 0 8px; color: #1967d2; font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.65rem); line-height: 1.08; } .intro { margin: 14px 0 30px; color: #697079; }
label { display: block; margin-bottom: 8px; font-size: .9rem; font-weight: 700; } .input-row { display: flex; gap: 10px; }
input { min-width: 0; flex: 1; padding: 14px 16px; border: 1px solid #c8cdd2; border-radius: 12px; font: inherit; }
input:focus { outline: 3px solid #1a73e822; border-color: #1a73e8; }
button { padding: 14px 22px; border: 0; border-radius: 12px; color: #fff; background: #1a73e8; font: inherit; font-weight: 750; cursor: pointer; }
button:hover { background: #155fc0; } button:disabled { opacity: .6; cursor: wait; }
.status { min-height: 24px; margin: 16px 0 0; color: #59636e; } .status.error { color: #b3261e; }
.result { margin-top: 26px; border-top: 1px solid #e6e9ec; padding-top: 26px; } .summary { display: flex; gap: 54px; margin-bottom: 26px; }
.summary span { display: block; font-size: 2rem; font-weight: 800; } .summary small { color: #737b84; }
.rating-row { display: grid; grid-template-columns: 42px 1fr 70px; align-items: center; gap: 12px; margin: 11px 0; }
.rating-row > span { color: #9a6700; font-weight: 700; } .rating-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 10px; overflow: hidden; border-radius: 99px; background: #edf0f2; } .bar i { display: block; height: 100%; border-radius: inherit; background: #fbbc04; }
@media (max-width: 560px) { .input-row { flex-direction: column; } button { width: 100%; } }