Skip to content

Commit cf7594f

Browse files
committedFeb 19, 2021
Refactor frontend, add list of flights
1 parent e03ab04 commit cf7594f

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed
 

‎src/views/index.html

+32-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<h1>Search a best price</h1>
1919

2020
<div class="row">
21-
<div class="col">
22-
<div class="list-group" id="airportList"></div>
23-
</div>
2421
<div class="col">
2522
<form class="row g-3 needs-validation" id="formBestPrice" novalidate>
2623
<div class="col-md-6 mb-3">
@@ -75,6 +72,15 @@ <h1>Search a best price</h1>
7572
</div>
7673
</div>
7774
</div>
75+
76+
<div class="row">
77+
<div class="col">
78+
<div class="list-group" id="airportList"></div>
79+
</div>
80+
<div class="col">
81+
<ul class="list-group" id="flightList"></ul>
82+
</div>
83+
</div>
7884
</div>
7985

8086
<script
@@ -111,6 +117,29 @@ <h5 class="mb-1">${airport.name}</h5>
111117
});
112118
});
113119

120+
/* Get All Flights */
121+
fetch("/flight")
122+
.then((response) => response.json())
123+
.then((data) => {
124+
data.forEach((flight) => {
125+
let item = document.createElement("li");
126+
item.classList.add(
127+
"list-group-item",
128+
"d-flex",
129+
"justify-content-between"
130+
);
131+
item.innerHTML = `
132+
${flight.code_departure} -> ${flight.code_arrival}
133+
<span class='h4' >&euro; ${flight.price}</span>
134+
`;
135+
136+
document.querySelector("#flightList").appendChild(item);
137+
});
138+
})
139+
.catch((e) => {
140+
console.error(e);
141+
});
142+
114143
let form = document.querySelector("#formBestPrice");
115144
form.addEventListener(
116145
"submit",

0 commit comments

Comments
 (0)
Please sign in to comment.