Compare commits
No commits in common. "main" and "feature/mobile-desktop-version" have entirely different histories.
main
...
feature/mo
@ -89,18 +89,14 @@ footer {
|
|||||||
|
|
||||||
.search__controls {
|
.search__controls {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.search__controls input,
|
.search__controls input {
|
||||||
.search__controls select {
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 120px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.search__controls button {
|
.search__controls button {
|
||||||
flex: 0 0 auto;
|
width: 150px;
|
||||||
min-width: 120px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#event-list {
|
#event-list {
|
||||||
|
|||||||
19
index.html
19
index.html
@ -42,13 +42,12 @@
|
|||||||
<main class="container mt-4">
|
<main class="container mt-4">
|
||||||
|
|
||||||
<!-- SEARCH / FILTER SECTION -->
|
<!-- SEARCH / FILTER SECTION -->
|
||||||
<section class="search mb-4">
|
<section class="event-search mb-4">
|
||||||
|
|
||||||
<h2>Find Events</h2>
|
<h2>Find Events</h2>
|
||||||
|
|
||||||
<div class="search__controls">
|
<div class="search__controls">
|
||||||
|
|
||||||
<!-- City -->
|
|
||||||
<input
|
<input
|
||||||
id="city-input"
|
id="city-input"
|
||||||
type="text"
|
type="text"
|
||||||
@ -56,22 +55,6 @@
|
|||||||
placeholder="Enter city (e.g. Zurich)"
|
placeholder="Enter city (e.g. Zurich)"
|
||||||
>
|
>
|
||||||
|
|
||||||
<!-- Date -->
|
|
||||||
<label for="date-from">From</label>
|
|
||||||
<input id="date-from" type="date">
|
|
||||||
|
|
||||||
<label for="date-to">To</label>
|
|
||||||
<input id="date-to" type="date">
|
|
||||||
|
|
||||||
<!-- Category -->
|
|
||||||
<select id="category-input" class="form-control">
|
|
||||||
<option value="">All categories</option>
|
|
||||||
<option value="music">Music</option>
|
|
||||||
<option value="sports">Sports</option>
|
|
||||||
<option value="arts & theatre">Arts & Theatre</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- Button -->
|
|
||||||
<button
|
<button
|
||||||
id="load-events"
|
id="load-events"
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
|
|||||||
53
js/app.js
53
js/app.js
@ -1,46 +1,39 @@
|
|||||||
import { getEvents } from "./services/eventService.js";
|
import { fetchEvents } from "./api/ticketmaster.js";
|
||||||
import { renderEventList } from "./ui/eventList.js";
|
import { createEventCard } from "./ui/eventCard.js";
|
||||||
import { getFilters } from "./ui/filters.js";
|
|
||||||
|
|
||||||
const button = document.querySelector("#load-events");
|
const button = document.querySelector("#load-events");
|
||||||
const container = document.querySelector("#event-list");
|
const container = document.querySelector("#event-list");
|
||||||
const cityInput = document.querySelector("#city-input");
|
const cityInput = document.querySelector("#city-input");
|
||||||
|
|
||||||
button.addEventListener("click", handleSearch);
|
button.addEventListener("click", async () => {
|
||||||
|
|
||||||
cityInput.addEventListener("keydown", (event) => {
|
const city = cityInput.value.trim();
|
||||||
if (event.key === "Enter") handleSearch();
|
|
||||||
});
|
|
||||||
|
|
||||||
async function handleSearch() {
|
|
||||||
|
|
||||||
const { city, dateFrom, dateTo, category } = getFilters();
|
|
||||||
|
|
||||||
if (!city) {
|
if (!city) {
|
||||||
container.innerHTML = "<p class='text-danger'>Please enter a city.</p>";
|
container.innerHTML = "Please enter a city.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.innerHTML = "<p class='text-muted'>Loading events...</p>";
|
container.innerHTML = "Loading events...";
|
||||||
|
|
||||||
const events = await getEvents(city);
|
const events = await fetchEvents(city);
|
||||||
|
|
||||||
const filteredEvents = applyFilters(events, dateFrom, dateTo, category);
|
container.innerHTML = "";
|
||||||
|
|
||||||
renderEventList(filteredEvents, container);
|
if (events.length === 0) {
|
||||||
}
|
container.innerHTML = "No events found.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function applyFilters(events, dateFrom, dateTo, category) {
|
events.forEach(event => {
|
||||||
|
const card = createEventCard(event);
|
||||||
return events.filter(event => {
|
container.appendChild(card);
|
||||||
|
|
||||||
const matchDateFrom = dateFrom ? event.date >= dateFrom : true;
|
|
||||||
const matchDateTo = dateTo ? event.date <= dateTo : true;
|
|
||||||
|
|
||||||
const matchCategory = category
|
|
||||||
? event.category && event.category.includes(category)
|
|
||||||
: true;
|
|
||||||
|
|
||||||
return matchDateFrom && matchDateTo && matchCategory;
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
});
|
||||||
|
|
||||||
|
cityInput.addEventListener("keydown", (event) => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
button.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -6,11 +6,7 @@ export async function getEvents(city) {
|
|||||||
return events.map(event => ({
|
return events.map(event => ({
|
||||||
id: event.id,
|
id: event.id,
|
||||||
name: event.name,
|
name: event.name,
|
||||||
date: event.dates?.start?.localDate || null,
|
date: event.dates.start.localDate,
|
||||||
time: event.dates?.start?.localTime || null,
|
venue: event._embedded?.venues[0]?.name
|
||||||
venue: event._embedded?.venues?.[0]?.name || "Unknown venue",
|
|
||||||
category: event.classifications?.[0]?.segment?.name
|
|
||||||
? event.classifications[0].segment.name.toLowerCase()
|
|
||||||
: null
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -1,37 +1,17 @@
|
|||||||
export function createEventCard(event) {
|
export function createEventCard(event) {
|
||||||
|
|
||||||
const article = document.createElement("article");
|
const article = document.createElement("article");
|
||||||
article.className = "event-card";
|
article.className = "event-card";
|
||||||
|
|
||||||
const title = document.createElement("h3");
|
const name = event.name;
|
||||||
title.className = "event-card__title";
|
const date = event.dates.start.localDate;
|
||||||
title.textContent = event.name;
|
const venue = event._embedded?.venues[0]?.name;
|
||||||
|
|
||||||
const formattedDate = event.date
|
article.innerHTML = `
|
||||||
? new Date(event.date).toLocaleDateString("de-CH", {
|
<h3 class="event-card__title">${name}</h3>
|
||||||
day: "2-digit",
|
<p class="event-card__date">${date}</p>
|
||||||
month: "2-digit",
|
<p class="event-card__venue">${venue}</p>
|
||||||
year: "numeric"
|
`;
|
||||||
})
|
|
||||||
: "Date not available";
|
|
||||||
|
|
||||||
const formattedTime = event.time
|
return article;
|
||||||
? event.time.slice(0, 5)
|
}
|
||||||
: "";
|
|
||||||
|
|
||||||
const dateTime = formattedTime
|
|
||||||
? `${formattedDate}, ${formattedTime}`
|
|
||||||
: formattedDate;
|
|
||||||
|
|
||||||
const date = document.createElement("p");
|
|
||||||
date.className = "event-card__date";
|
|
||||||
date.textContent = dateTime;
|
|
||||||
|
|
||||||
const venue = document.createElement("p");
|
|
||||||
venue.className = "event-card__venue";
|
|
||||||
venue.textContent = event.venue;
|
|
||||||
|
|
||||||
article.append(title, date, venue);
|
|
||||||
|
|
||||||
return article;
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
import { createEventCard } from "./eventCard.js";
|
|
||||||
|
|
||||||
export function renderEventList(events, container) {
|
|
||||||
|
|
||||||
container.innerHTML = "";
|
|
||||||
|
|
||||||
if (events.length === 0) {
|
|
||||||
container.innerHTML = "No events found.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
events.forEach(event => {
|
|
||||||
const card = createEventCard(event);
|
|
||||||
container.appendChild(card);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
export function getFilters() {
|
|
||||||
const city = document.querySelector("#city-input").value.trim();
|
|
||||||
const dateFrom = document.querySelector("#date-from").value;
|
|
||||||
const dateTo = document.querySelector("#date-to").value;
|
|
||||||
const category = document.querySelector("#category-input").value;
|
|
||||||
|
|
||||||
return { city, dateFrom, dateTo, category };
|
|
||||||
}
|
|
||||||
3
js/utils/helpers.js
Normal file
3
js/utils/helpers.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function formatDate(date) {
|
||||||
|
return new Date(date).toLocaleDateString();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user