diff --git a/Backend/peepal_backend/.gitignore b/Backend/peepal_backend/.gitignore index c7cf1fa..3d8cf3d 100644 --- a/Backend/peepal_backend/.gitignore +++ b/Backend/peepal_backend/.gitignore @@ -6,7 +6,6 @@ /storage/*.key /storage/pail /vendor -.env .env.backup .env.production .phpactor.json diff --git a/frontend/peepal_react/src/App.js b/frontend/peepal_react/src/App.js index 6fa6926..20abb10 100644 --- a/frontend/peepal_react/src/App.js +++ b/frontend/peepal_react/src/App.js @@ -1,22 +1,18 @@ import Bejelentkezes from './WC_Komponens/Bejel_Regisz/Bejelentkezes'; import Regisztracio from './WC_Komponens/Bejel_Regisz/Regisztracio'; -import Kereso from './WC_Komponens/Kereso/WC_Kereso'; import Menusor from './NavBar/Menusor'; import { Route, Routes } from 'react-router-dom'; import Kezdolap from './WC_Komponens/Kezdolap/Kezdolap'; -import Fejlec from './WC_Komponens/Fejlec/Fejlec'; -import HozzaadGomb from './WC_Komponens/Hozzadas/HozzaadGomb'; +import LegkozelebbiMosdo from './WC_Komponens/Kereso/Legkozelebbi'; export default function App() { return ( <> - -
}/> - }/> + }/> }/> } /> diff --git a/frontend/peepal_react/src/WC_Komponens/Hozzadas/HozzaadGomb.jsx b/frontend/peepal_react/src/WC_Komponens/Hozzadas/HozzaadGomb.jsx index 2474059..3745ed4 100644 --- a/frontend/peepal_react/src/WC_Komponens/Hozzadas/HozzaadGomb.jsx +++ b/frontend/peepal_react/src/WC_Komponens/Hozzadas/HozzaadGomb.jsx @@ -1,7 +1,11 @@ -export default function HozzaadGomb(){ - return( - <> - - - ) -} \ No newline at end of file +import { Plus } from "lucide-react"; + +export default function HozzaadGomb() { + return ( + + ); +} diff --git a/frontend/peepal_react/src/WC_Komponens/Kereso/Legkozelebbi.jsx b/frontend/peepal_react/src/WC_Komponens/Kereso/Legkozelebbi.jsx index 31b12f4..56f98b3 100644 --- a/frontend/peepal_react/src/WC_Komponens/Kereso/Legkozelebbi.jsx +++ b/frontend/peepal_react/src/WC_Komponens/Kereso/Legkozelebbi.jsx @@ -1,9 +1,153 @@ -import Csempe from "../Budi_Blokk/Csempe"; +import React, { useState, useEffect } from 'react'; +import { mosdokFetch } from '../../apiFetch'; -export default function LegkozelebbiMosdo(){ - return( - <> - - - ) +// Haversine formula to calculate distance between two coordinates +const calculateDistance = (lat1, lon1, lat2, lon2) => { + const R = 6371; // Earth's radius in kilometers + const dLat = (lat2 - lat1) * Math.PI / 180; + const dLon = (lon2 - lon1) * Math.PI / 180; + const a = + Math.sin(dLat/2) * Math.sin(dLat/2) + + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * + Math.sin(dLon/2) * Math.sin(dLon/2); + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + return R * c; // Distance in kilometers +}; + +export default function LegkozelebbiMosdo() { + const [nearestRestroom, setNearestRestroom] = useState(null); + const [userLocation, setUserLocation] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(false); + + const findNearestRestroom = async (latitude, longitude) => { + setLoading(true); + try { + // Fetch restrooms from the API + const mosdok = await mosdokFetch(); + + // Find the nearest restroom + let nearest = null; + let minDistance = Infinity; + + mosdok.forEach(mosdo => { + // Use hossz_koord and szel_koord instead of latitude/longitude + if (mosdo.hossz_koord && mosdo.szel_koord) { + const distance = calculateDistance( + latitude, + longitude, + mosdo.szel_koord, + mosdo.hossz_koord + ); + + if (distance < minDistance) { + minDistance = distance; + nearest = mosdo; + } + } + }); + + if (nearest) { + // Add the calculated distance to the nearest restroom object + nearest.distanceKm = minDistance.toFixed(2); + setNearestRestroom(nearest); + } else { + setError("Nem találtunk elérhető mosdót a közelben."); + } + } catch (err) { + setError("Hiba történt a mosdók lekérésekor."); + console.error(err); + } finally { + setLoading(false); + } + }; + + const handleLocationPermission = () => { + if ("geolocation" in navigator) { + setLoading(true); + navigator.geolocation.getCurrentPosition( + (position) => { + const { latitude, longitude } = position.coords; + setUserLocation({ latitude, longitude }); + findNearestRestroom(latitude, longitude); + }, + (error) => { + setError("Nem sikerült lekérni a tartózkodási helyét: " + error.message); + setLoading(false); + } + ); + } else { + setError("A helymeghatározás nem elérhető a böngészőben."); + } + }; + + // Render loading state + if (loading) { + return ( +
+
+
+ ); + } + + // Render error state + if (error) { + return
{error}
; + } + + // Render nearest restroom details + if (nearestRestroom) { + return ( +
+

Legközelebbi mosdó

+
+

{nearestRestroom.nev}

+

Kerület: {nearestRestroom.kerulet}

+

Legközelebbi megálló: {nearestRestroom.kozeli_megall}

+

Ár: {nearestRestroom.ar} Ft

+

Nyitvatartás: {nearestRestroom.nyitva}

+ + + Útvonalterv + +
+ + {nearestRestroom.akadalym && ( + wheelchair + )} +
+ ); + } + + // Default render (before location permission) + return ( +
+
+

Helyzetmeghatározás

+

Engedélyezed a helyzetmeghatározást?

+
+ + +
+
+
+ ); } \ No newline at end of file diff --git a/frontend/peepal_react/src/WC_Komponens/Kereso/WC_Kereso.jsx b/frontend/peepal_react/src/WC_Komponens/Kereso/WC_Kereso.jsx deleted file mode 100644 index cd56eb4..0000000 --- a/frontend/peepal_react/src/WC_Komponens/Kereso/WC_Kereso.jsx +++ /dev/null @@ -1,19 +0,0 @@ -export default function Kereso() { - return ( -
-
-

Helyzetmeghatározás

-

Engedélyezed a helyzetmeghatározást?

-
- - -
-
-
- ); -} - \ No newline at end of file diff --git a/frontend/peepal_react/src/WC_Komponens/Kezdolap/Kezdolap.jsx b/frontend/peepal_react/src/WC_Komponens/Kezdolap/Kezdolap.jsx index 1cb54d1..743768f 100644 --- a/frontend/peepal_react/src/WC_Komponens/Kezdolap/Kezdolap.jsx +++ b/frontend/peepal_react/src/WC_Komponens/Kezdolap/Kezdolap.jsx @@ -1,9 +1,13 @@ import Csempe from "../Budi_Blokk/Csempe"; +import Fejlec from "../Fejlec/Fejlec"; +import HozzaadGomb from "../Hozzadas/HozzaadGomb"; export default function Kezdolap(){ return( <> + + ) } \ No newline at end of file