Skip to content

Commit

Permalink
Change directories
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisseurin committed Jul 24, 2024
1 parent 9c6736b commit df8a7e4
Show file tree
Hide file tree
Showing 35 changed files with 126 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
publish_dir: dist
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 1 addition & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,9 @@
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<title>Public Transport Map</title>
<base href=".">
<script type="text/javascript">
// Single Page Apps for GitHub Pages
// MIT License
// https://github.com/rafgraph/spa-github-pages
// This script checks to see if a redirect is present in the query string,
// converts it back into the correct url and adds it to the
// browser's history using window.history.replaceState(...),
// which won't cause the browser to attempt to load the new url.
// When the single page app is loaded further down in this file,
// the correct url will be waiting in the browser's history for
// the single page app to route accordingly.
(function (l) {
if (l.search[1] === '/') {
var decoded = l.search.slice(1).split('&').map(function (s) {
return s.replace(/~and~/g, '&')
}).join('?');
window.history.replaceState(null, null,
l.pathname.slice(0, -1) + decoded + l.hash
);
}
}(window.location))
</script>
</head>
<body>
<div id="root"></div>
<script src="/public-transport-map/src/main.tsx" type="module" ></script>
<script src="./src/main.tsx" type="module" ></script>
</body>
</html>
2 changes: 1 addition & 1 deletion public-transport-map/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState, useMemo, useCallback } from 'react';
import Map from "./components/Map";
import StatCounter from "./components/StatCounter";
import { RouteData, StopData, TrainData } from './types';
import { RouteData, StopData, TrainData } from '../../src/types';
import LinesDisplay from './components/LinesDisplay';
import './App.css';
import "leaflet/dist/leaflet.css";
Expand Down
File renamed without changes.
120 changes: 120 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { useEffect, useState, useMemo, useCallback } from 'react';
import Map from "./components/Map";
import StatCounter from "./components/StatCounter";
import { RouteData, StopData, TrainData } from './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";

function App() {
const [routes, setRoutes] = useState<RouteData[]>([]);
const [stops, setStops] = useState<StopData[]>([]);
const [trains, setTrains] = useState<TrainData[]>([]);
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 (
<div className="app-container">
<div className="top-left-text">
<span>Public transport map</span>
</div>
<div className="bottom-left-stats">
<StatCounter icon={routePlaceholder} label="lines" count={RouteCount} />
<StatCounter icon={stopPlaceholder} label="stops" count={stopCount} />
<StatCounter icon={trainPlaceholder} label="trams, subways and buses" count={trainCount} />
</div>
<LinesDisplay
isLineDisplayVisible={isLineDisplayVisible}
toggleStatsVisibility={toggleStatsVisibility}
/>
{isLoaded && <Map routes={routes} stops={stops} trains={trains} />}
</div>
);
}

export default App;
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions public-transport-map/src/main.tsx → src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { HashRouter as Router } from 'react-router-dom';
import App from './App.tsx';

ReactDOM.createRoot(document.getElementById('root')!).render(
// <React.StrictMode>
<React.StrictMode>
<Router>
<App />
</Router>
//</React.StrictMode>,
</React.StrictMode>,
);
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"include": ["src", "src/App.tsx", "public-transport-map/src/main.tsx"],
"references": [{ "path": "./tsconfig.node.json" }]
}
File renamed without changes.
1 change: 0 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import react from '@vitejs/plugin-react-swc'

export default defineConfig({
plugins: [react()],
base: '/public-transport-map/', // Remplacez par le nom de votre dépôt GitHub
build: {
outDir: 'dist', // Le dossier de sortie pour les fichiers transpilés
},
Expand Down

0 comments on commit df8a7e4

Please sign in to comment.