Skip to content

Commit

Permalink
bug fixes and optimalization
Browse files Browse the repository at this point in the history
  • Loading branch information
pakut2 committed Feb 24, 2021
1 parent f54df45 commit 4475202
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 53 deletions.
6 changes: 4 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ form button:hover {
opacity: 0;
}

.offline {
.offline,
.location {
padding-right: 0.5rem;
padding-left: 0.5rem;
}
.offline span {
.offline span,
.location span {
display: flex;
justify-content: center;
align-content: center;
Expand Down
63 changes: 32 additions & 31 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ const app = () => {
return;
}

for (let i = 0; i < stops.length; i++) {
let dataArr;

stops.filter((stop) => {
if (
latinize(stops[i].stopName) === latinize(input) &&
stops[i].stopCode === "01" &&
stops[i].zoneId === 1
latinize(stop.stopName) === latinize(input) &&
stop.stopCode === "01" &&
stop.zoneId === 1
) {
let ID = stops[i].stopId;
let dataArr = [ID, stops[i].stopName];
return dataArr;
let ID = stop.stopId;
dataArr = [ID, stop.stopName];
}
}
});
return dataArr;
};

const getTimeData = async () => {
Expand Down Expand Up @@ -300,45 +302,45 @@ const app = () => {
}

if (directionId === "01") {
for (let i = 0; i < stops.length; i++) {
stops.filter((stopArg) => {
if (
stops[i].stopName === input &&
stops[i].stopCode === "02" &&
stops[i].zoneId === 1
stopArg.stopName === input &&
stopArg.stopCode === "02" &&
stopArg.zoneId === 1
) {
ID = stops[i].stopId;
ID = stopArg.stopId;
stop1[3].children[1].innerText = ID;
dataArr = [ID, stops[i].stopName];
dataArr = [ID, stopArg.stopName];
stop1[3].children[0].innerText = "02";
stop1[3].children[0].classList.add("hidden");
directionId = stop1[3].children[0].innerText;
directions[terminus.indexOf(stop)] = directionId;

localStorage.setItem("directions", JSON.stringify(directions));
}
}
});
} else if (directionId === "02") {
if (input === "Wały Piastowskie") {
input = "Wały Piastowskie ";
}
for (let i = 0; i < stops.length; i++) {

stops.filter((stopArg) => {
if (
stops[i].stopName === input &&
stops[i].stopCode === "01" &&
stops[i].zoneId === 1
stopArg.stopName === input &&
stopArg.stopCode === "01" &&
stopArg.zoneId === 1
) {
ID = stops[i].stopId;

ID = stopArg.stopId;
stop1[3].children[1].innerText = ID;
dataArr = [ID, stops[i].stopName];
dataArr = [ID, stopArg.stopName];
stop1[3].children[0].innerText = "01";
stop1[3].children[0].classList.add("hidden");
directionId = stop1[3].children[0].innerText;
directions[terminus.indexOf(stop)] = directionId;

localStorage.setItem("directions", JSON.stringify(directions));
}
}
});
}

API_URL = `https://ckan2.multimediagdansk.pl/delays?stopId=${ID}`;
Expand Down Expand Up @@ -452,17 +454,16 @@ const app = () => {
let ID;
let dataArr = [];

for (let i = 0; i < stops.length; i++) {
stops.filter((stop) => {
if (
stops[i].stopName === input &&
stops[i].stopCode === directions[terminus.indexOf(input)] &&
stops[i].zoneId === 1
stop.stopName === input &&
stop.stopCode === directions[terminus.indexOf(input)] &&
stop.zoneId === 1
) {
ID = stops[i].stopId;

dataArr = [ID, stops[i].stopName];
ID = stop.stopId;
dataArr = [ID, stop.stopName];
}
}
});

const ID_API_URL = `https://ckan2.multimediagdansk.pl/delays?stopId=${ID}`;

Expand Down
26 changes: 20 additions & 6 deletions js/directSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ const app = () => {
return dataArr;
}
}

let dataArr = [];

stops.filter((stop) => {
if (
latinize(stop.stopName) === latinize(input) &&
stop.stopCode === code &&
stop.zoneId === 1
) {
let ID = stop.stopId;
dataArr = [ID, `${stop.stopName} ${stop.stopCode}`];
}
});
return dataArr;
};

const getTimeData = async () => {
Expand Down Expand Up @@ -302,15 +316,15 @@ const app = () => {

let ID;

for (let i = 0; i < stops.length; i++) {
stops.filter((stop) => {
if (
stops[i].stopName === input &&
stops[i].stopCode === code &&
stops[i].zoneId === 1
stop.stopName === input &&
stop.stopCode === code &&
stop.zoneId === 1
) {
ID = stops[i].stopId;
ID = stop.stopId;
}
}
});

ID_API_URL = `https://ckan2.multimediagdansk.pl/delays?stopId=${ID}`;

Expand Down
36 changes: 22 additions & 14 deletions js/localSearchApp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const prompt = document.querySelector(".offline");
const userLocation = document.querySelector(".location");

window.addEventListener("load", () => {
const handleConnection = () => {
Expand Down Expand Up @@ -62,21 +63,21 @@ const successCallback = (position) => {
let array = [];
let dataArr = [];

for (let i = 0; i < stops.length; i++) {
const distance = calDist(lat1, lon1, stops[i].stopLat, stops[i].stopLon);
stops.filter((stop) => {
const distance = calDist(lat1, lon1, stop.stopLat, stop.stopLon);
if (distance <= 500) {
let ID = stops[i].stopId;
// dataArr = [ID, stops[i].stopName];
let ID = stop.stopId;

dataArr.push(Math.round(distance));
dataArr.push(ID);
dataArr.push(stops[i].stopName);
dataArr.push(stops[i].stopLon);
dataArr.push(stops[i].stopLat);
dataArr.push(stops[i].stopCode);
dataArr.push(stop.stopName);
dataArr.push(stop.stopLon);
dataArr.push(stop.stopLat);
dataArr.push(stop.stopCode);
array.push(dataArr);
dataArr = [];
}
}
});
return array;
};

Expand All @@ -90,6 +91,12 @@ const successCallback = (position) => {

const getTimeData = async () => {
const array = await getIdData();

if (array.length === 0) {
userLocation.classList.remove("indicator");
return;
}

//console.log(array.sort(sortFunction));
array.sort(sortFunction);

Expand Down Expand Up @@ -212,10 +219,10 @@ const successCallback = (position) => {
}
};

getTimeData().catch((error) => {
console.error();
});
// getTimeData();
// getTimeData().catch((error) => {
// console.error();
// });
getTimeData();

//get vehicle ids
const getVehicleCodes = async (ID) => {
Expand Down Expand Up @@ -385,7 +392,7 @@ const successCallback = (position) => {
marker.remove();
});

geojson.features.forEach(function (marker) {
geojson.features.forEach((marker) => {
const element = document.createElement("div");
element.innerHTML = '<i class="fas fa-bus"></i>';
element.className = "marker";
Expand Down Expand Up @@ -453,6 +460,7 @@ const successCallback = (position) => {

const errorCallback = (error) => {
console.log(error.message);
userLocation.classList.remove("indicator");
};

const app = () => {
Expand Down
9 changes: 9 additions & 0 deletions views/localSearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ <h4>Closer</h4>
from the internet until you reconnect.</span
>
</div>
<div class="location indicator">
<span class="header"
>It looks like you forbid user localization.</span
>
<span class="footer"
>In order to experience all features, please refresh and allow
user localization.</span
>
</div>
<div class="map-container">
<button class="remove-map-button indicator">
<i class="fas fa-times"></i>
Expand Down

0 comments on commit 4475202

Please sign in to comment.