From 704d59e2f731f7959368ba1d50c3796804abfbd4 Mon Sep 17 00:00:00 2001 From: Alexis Seurin Date: Wed, 24 Jul 2024 14:14:33 +0200 Subject: [PATCH] Change svg --- public-transport-map/src/App.tsx | 121 ------------------------------- src/App.tsx | 3 +- 2 files changed, 2 insertions(+), 122 deletions(-) delete mode 100644 public-transport-map/src/App.tsx diff --git a/public-transport-map/src/App.tsx b/public-transport-map/src/App.tsx deleted file mode 100644 index 6a1a462..0000000 --- a/public-transport-map/src/App.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import { useEffect, useState, useMemo, useCallback } from 'react'; -import Map from "./components/Map"; -import StatCounter from "./components/StatCounter"; -import { RouteData, StopData, TrainData } from '../../src/types'; -import LinesDisplay from './components/LinesDisplay'; -import './App.css'; -import "leaflet/dist/leaflet.css"; -import './components/Icon.css'; -import './components/StatCounter.css'; -import stopPlaceholder from "./assets/stop.svg"; -import trainPlaceholder from "./assets/train.svg"; -import routePlaceholder from "./assets/road.svg"; -import React from 'react'; - -function App() { - const [routes, setRoutes] = useState([]); - const [stops, setStops] = useState([]); - const [trains, setTrains] = useState([]); - const [isLoaded, setIsLoaded] = useState(false); - const [isLineDisplayVisible, setisLineDisplayVisible] = useState(false); - - const updateTrainPositions = useCallback((newTrains: TrainData[]) => { - setTrains(newTrains); - }, []); - - useEffect(() => { - - - Promise.all([ - fetch('data/gtfs-routes-production.json').then(response => response.json()), - fetch('data/gtfs-stops-production.json').then(response => response.json()), - fetch('data/vehicle-position-rt-production.json').then(response => response.json()), - fetch('data/stop-details-production.json').then(response => response.json()), - fetch('data/stops-by-line-production.json').then(response => response.json()) - ]).then(([routesData, stopsData, trainsData, stopDetailsData, stopsByLineData]) => { - console.log('Routes, stops, and trains loaded'); - - const combinedStopsData = stopsData.map((stop: { stop_id: string; stop_name: string; }) => { - const stopDetails = stopDetailsData.find((detail: { id: string; name: string; }) => detail.id === stop.stop_id); - const stopName = stopDetails ? JSON.parse(stopDetails.name.replace(/\\/g, '')) : { fr: stop.stop_name, nl: stop.stop_name }; - - let ordersAndLineIds: { order: any; lineid: string; }[] = []; - stopsByLineData.forEach((line: { lineid: string, points: string }) => { - const points = JSON.parse(line.points); - const stopPoint = points.find((point: { id: string; order: number }) => point.id === stop.stop_id); - if (stopPoint) { - ordersAndLineIds.push({ order: stopPoint.order, lineid: line.lineid }); - } - }); - - return { - ...stop, - stop_name: stopName, - ordersAndLineIds: ordersAndLineIds - }; - }); - - - setRoutes(routesData); - setStops(combinedStopsData); - updateTrainPositions(trainsData); - setIsLoaded(true); - }).catch(error => { - console.error('Error loading data:', error); - }); - - const fetchTrainData = () => { - fetch('data/vehicle-position-rt-production.json') - .then(response => response.json()) - .then(data => { - console.log('Trains loaded:', data); - setTrains(data); - }) - .catch(error => { - console.error('Error loading trains:', error); - }); - }; - - fetchTrainData(); // Initial fetch - const interval = setInterval(fetchTrainData, 20000); // Fetch every 20 seconds - - return () => clearInterval(interval); // Cleanup on unmount - }, [updateTrainPositions]); - - - const { RouteCount, stopCount, trainCount } = useMemo(() => { - const totalRoutes = routes.length; - const totalStops = stops.length; - const totalTrains = trains.length; - - return { - RouteCount: totalRoutes, - stopCount: totalStops, - trainCount: totalTrains - }; - }, [routes, stops, trains]); - - const toggleStatsVisibility = () => { - setisLineDisplayVisible(!isLineDisplayVisible); - }; - - return ( -
-
- Public transport map -
-
- - - -
- - {isLoaded && } -
- ); - } - -export default App; diff --git a/src/App.tsx b/src/App.tsx index 7f5696b..f6b98eb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,8 +8,9 @@ import "leaflet/dist/leaflet.css"; import './components/Icon.css'; import './components/StatCounter.css'; import stopPlaceholder from "./assets/stop.svg"; -import trainPlaceholder from "/assets/train.svg"; +import trainPlaceholder from "./assets/train.svg"; import routePlaceholder from "./assets/road.svg"; +//import React from 'react'; function App() { const [routes, setRoutes] = useState([]);