diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index bf0d4f2..32b0e8a 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -2,6 +2,7 @@ import React, { useState } from "react"; import Sidebar from "./components/Sidebar"; import MapComponent from "./components/MapComponent"; import LoadingOverlay from "./components/LoadingOverlay"; +import LuasPopup from "./components/LuasPopup"; const TRANSIENT_DATA_API = "https://281bc6mcm5.execute-api.us-east-1.amazonaws.com/transient_data"; const PERMANENT_DATA_API = "https://a6y312dpuj.execute-api.us-east-1.amazonaws.com/permanent_data"; @@ -143,6 +144,26 @@ function App() { ); break; + case "LuasStop": + objectTitle = item.luasStopName + " Luas Stop"; + let luasLine; + + switch (item.luasStopLineID) { + case "1": + luasLine = "Green Line"; + break; + case "2": + luasLine = "Red Line"; + break; + default: + luasLine = "N/A"; + } + + popupContent = ( + + ); + break; + default: popupContent = (
diff --git a/frontend/src/components/LuasPopup.jsx b/frontend/src/components/LuasPopup.jsx new file mode 100644 index 0000000..fdf4b0b --- /dev/null +++ b/frontend/src/components/LuasPopup.jsx @@ -0,0 +1,45 @@ +import React, { useState } from "react"; + +const LuasPopup = ({ item, objectTitle, luasLine }) => { + const [luasInfo, setLuasInfo] = useState(""); + + const fetchLuasData = async () => { + try { + const response = await fetch(`http://luasforecasts.rpa.ie/xml/get.ashx?action=forecast&stop=${item.luasStopCode}&encrypt=false`); + const text = await response.text(); + const parser = new DOMParser(); + const xml = parser.parseFromString(text, "text/xml"); + const trams = Array.from(xml.getElementsByTagName("tram")); + + if (trams.length === 0) { + setLuasInfo("No trams available"); + return; + } + + const tramInfo = trams.map(tram => `Destination: ${tram.getAttribute("destination")}, Arrival: ${tram.getAttribute("dueMins")} mins`).join("
"); + setLuasInfo(tramInfo); + } catch (error) { + setLuasInfo("Failed to fetch Luas data"); + } + }; + + return ( +
+

{objectTitle}

+
    +
  • Luas Stop Name: {item.luasStopName} / {item.luasStopIrishName}
  • +
  • Line: {luasLine}
  • +
  • Stop ID: {item.luasStopID}
  • +
  • Park & ride?: {(item.luasStopIsParkAndRide === "1") ? "Yes" : "No"}
  • +
  • Cycle & ride?: {(item.luasStopIsCycleAndRide === "1") ? "Yes" : "No"}
  • +
  • Operational?: {(item.luasStopIsEnabled === "1") ? "Yes" : "No"}
  • +
+ +
+
+ ); +}; + +export default LuasPopup; \ No newline at end of file