Commit bd394c4c authored by Lauren Liberda's avatar Lauren Liberda
Browse files

fix crash on rick-roll pickup points (WTF InPost?!)

parent 0abedfc1
Pipeline #236 passed with stage
in 28 seconds
......@@ -268,16 +268,21 @@ const refreshPackages = async (response?: Package[]) => {
const details = row.insertCell(4);
const opener = row.insertCell(5);
row.dataset.pickupPointLat = shipment.pickupPoint.location.latitude.toString();
row.dataset.pickupPointLon = shipment.pickupPoint.location.longitude.toString();
// apparently there are rick-roll pickup points
if (shipment.pickupPoint.location) {
row.dataset.pickupPointLat = shipment.pickupPoint.location.latitude.toString();
row.dataset.pickupPointLon = shipment.pickupPoint.location.longitude.toString();
}
row.dataset.pickupPointDescription = shipment.pickupPoint.description;
row.dataset.pickupPointName = shipment.pickupPoint.name;
row.dataset.pickupPointStatus = shipment.pickupPoint.status;
row.dataset.pickupPointStreet = shipment.pickupPoint.address.street;
row.dataset.pickupPointStreetNumber = shipment.pickupPoint.address.buildingNumber;
row.dataset.pickupPointCity = shipment.pickupPoint.address.city;
row.dataset.pickupPointProvince = shipment.pickupPoint.address.province;
row.dataset.pickupPointPostCode = shipment.pickupPoint.address.postCode;
if (shipment.pickupPoint.address) {
row.dataset.pickupPointStreet = shipment.pickupPoint.address.street;
row.dataset.pickupPointStreetNumber = shipment.pickupPoint.address.buildingNumber;
row.dataset.pickupPointCity = shipment.pickupPoint.address.city;
row.dataset.pickupPointProvince = shipment.pickupPoint.address.province;
row.dataset.pickupPointPostCode = shipment.pickupPoint.address.postCode;
}
row.dataset.openCode = shipment.openCode;
row.dataset.id = shipment.shipmentNumber;
row.dataset.sender = shipment.senderName;
......@@ -296,44 +301,49 @@ const refreshPackages = async (response?: Package[]) => {
const detailsBox = document.querySelector(".details-box")! as HTMLDivElement;
detailsBox.style.display = "block";
const data = ((event.target as Element).parentNode!.parentNode as HTMLElement).dataset;
// maybe this looks like shit, but it works
let leafletLoaded = false;
try {
leafletLoaded = !!L;
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
if (data.pickupPointLat && data.pickupPointLon) {
showElements(["#map"]);
// maybe this looks like shit, but it works
let leafletLoaded = false;
try {
leafletLoaded = !!L;
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
if (!leafletLoaded) {
document.querySelector("head")!.appendChild(leafletLoaderCSS);
document.querySelector("head")!.appendChild(leafletLoaderJS);
await new Promise((resolve, reject) => {
leafletLoaderJS.addEventListener("load", () => {
resolve();
if (!leafletLoaded) {
document.querySelector("head")!.appendChild(leafletLoaderCSS);
document.querySelector("head")!.appendChild(leafletLoaderJS);
await new Promise<void>((resolve, reject) => {
leafletLoaderJS.addEventListener("load", () => {
resolve();
});
leafletLoaderJS.addEventListener("error", () => {
reject();
});
});
leafletLoaderJS.addEventListener("error", () => {
reject();
});
});
map = L.map("map");
}
map!.setView([parseFloat(data.pickupPointLat!), parseFloat(data.pickupPointLon!)], 17);
L.tileLayer("https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", {
attribution:
'Map data &copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
maxZoom: 19,
}).addTo(map!);
// delete previous markers
while (markers.length > 0) {
// @ts-ignore it's always marker, while loop checks length
map.removeLayer(markers.pop());
map = L.map("map");
}
map!.setView([parseFloat(data.pickupPointLat!), parseFloat(data.pickupPointLon!)], 17);
L.tileLayer("https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", {
attribution:
'Map data &copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
maxZoom: 19,
}).addTo(map!);
// delete previous markers
while (markers.length > 0) {
// @ts-ignore it's always marker, while loop checks length
map.removeLayer(markers.pop());
}
const marker = L.marker([
parseFloat(data.pickupPointLat!),
parseFloat(data.pickupPointLon!),
]).addTo(map!);
markers.push(marker);
} else {
hideElements(["#map"]);
}
const marker = L.marker([
parseFloat(data.pickupPointLat!),
parseFloat(data.pickupPointLon!),
]).addTo(map!);
markers.push(marker);
const openButton = detailsBox.querySelector(
".modal-card-foot button.is-primary",
)! as HTMLButtonElement;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment