Felesleges változók kivéve

This commit is contained in:
Sándor Máté Magony
2025-04-11 13:12:32 +02:00
parent 2975cd91b1
commit 3f0465fb5a
15 changed files with 187 additions and 147 deletions

View File

@@ -1,39 +1,4 @@
import React, { useState, useEffect } from 'react';
export default function Bejelentkezes() {
const [users, setUsers] = useState([]);
const fetchUsers = async () => {
try {
const response = await fetch('/users', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
// Include the CSRF token for Laravel if your API is protected
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'),
},
credentials: 'include', // Includes cookies in the request
});
console.log(response)
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
setUsers(data);
console.log(users)
} catch (err) {
console.log(err)
}
};
useEffect(() => {
fetchUsers();
}, []);
return (
<div className="flex justify-center items-center min-h-screen bg-yellow-100">
<form className="bg-white p-6 rounded-lg shadow-lg w-80 space-y-4">

View File

@@ -40,7 +40,7 @@ export default function Csempe() {
<div key={index} className="bg-white shadow-lg rounded-xl p-6 border border-gray-200 relative">
<h1 className="text-xl font-semibold text-gray-800 mb-3">{mosdo.nev}</h1>
<div className="text-gray-600 space-y-1">
<p><span className="font-medium text-gray-800">Kerület:</span> {mosdo.kerulet}</p>
<p><span className="font-medium text-gray-800">Kerület:</span> {mosdo.kerulet?.kerulet_nev}</p>
<p><span className="font-medium text-gray-800">Legközelebbi megálló:</span> {mosdo.kozeli_megall}</p>
<p><span className="font-medium text-gray-800">Ár:</span> {mosdo.ar} Ft</p>
<p><span className="font-medium text-gray-800">Nyitvatartás:</span> {mosdo.nyitva}</p>

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react";
import React, {useState} from "react";
import { useNavigate } from "react-router-dom";
export default function HozzaadForm() {
@@ -26,7 +26,7 @@ export default function HozzaadForm() {
koordinatak: koordinatak
}
fetch("http://localhost:8000/api/hozzaadas", {
fetch("http://192.168.0.78:8000/api/hozzaadas", {
method: "POST",
headers: {
"Content-Type": "application/json"

View File

@@ -1,6 +1,5 @@
import { Plus } from "lucide-react";
import { Link } from "react-router-dom";
import HozzaadForm from "./HozzaadForm";
export default function HozzaadGomb() {
return (

View File

@@ -1,18 +1,12 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { TfiWheelchair } from "react-icons/tfi";
import { mosdokFetch } from '../../apiFetch';
// Haversine formula to calculate distance between two coordinates
// Egyszerű koordináta-alapú távolság (nincs konverzió km-re)
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
const dx = lat1 - lat2;
const dy = lon1 - lon2;
return dx * dx + dy * dy; // távolság négyzete (nem baj, hogy nincs gyök alatt)
};
export default function LegkozelebbiMosdo() {
@@ -24,33 +18,27 @@ export default function LegkozelebbiMosdo() {
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,
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.");
@@ -70,6 +58,7 @@ export default function LegkozelebbiMosdo() {
(position) => {
const { latitude, longitude } = position.coords;
setUserLocation({ latitude, longitude });
console.log(userLocation);
findNearestRestroom(latitude, longitude);
},
(error) => {
@@ -82,7 +71,6 @@ export default function LegkozelebbiMosdo() {
}
};
// Render loading state
if (loading) {
return (
<div className="flex justify-center items-center h-32">
@@ -91,48 +79,47 @@ export default function LegkozelebbiMosdo() {
);
}
// Render error state
if (error) {
return <div className="text-center text-red-600 p-4">{error}</div>;
}
// Render nearest restroom details
if (nearestRestroom) {
return (
<div className="fixed inset-0 flex justify-center items-center">
<div className="bg-white shadow-lg rounded-xl p-6 border border-gray-200 relative">
<h1 className="text-xl font-semibold text-gray-800 mb-3">Legközelebbi mosdó</h1>
<div className="text-gray-600 space-y-2">
<h2 className="font-medium text-gray-800">{nearestRestroom.nev}</h2>
<p><span className="font-medium text-gray-800">Kerület:</span> {nearestRestroom.kerulet}</p>
<p><span className="font-medium text-gray-800">Legközelebbi megálló:</span> {nearestRestroom.kozeli_megall}</p>
<p><span className="font-medium text-gray-800">Ár:</span> {nearestRestroom.ar} Ft</p>
<p><span className="font-medium text-gray-800">Nyitvatartás:</span> {nearestRestroom.nyitva}</p>
<a
href={nearestRestroom.utvonal}
target="_blank"
rel="noopener noreferrer"
className="font-bold mt-4 inline-block bg-yellow-500 text-white py-2 px-4 rounded-lg shadow-md hover:bg-yellow-600 transition"
>
Útvonalterv
</a>
<div className="bg-white shadow-lg rounded-xl p-6 border border-gray-200 relative">
<h1 className="text-xl font-semibold text-gray-800 mb-3">Legközelebbi mosdó</h1>
<div className="text-gray-600 space-y-2">
<h2 className="font-medium text-gray-800">{nearestRestroom.nev}</h2>
<p><span className="font-medium text-gray-800">Kerület:</span> {nearestRestroom.kerulet?.kerulet_nev ?? 'Ismeretlen'}</p>
<p><span className="font-medium text-gray-800">Legközelebbi megálló:</span> {nearestRestroom.kozeli_megall}</p>
<p><span className="font-medium text-gray-800">Ár:</span> {nearestRestroom.ar} Ft</p>
<p><span className="font-medium text-gray-800">Nyitvatartás:</span> {nearestRestroom.nyitva}</p>
<a
href={nearestRestroom.utvonal}
target="_blank"
rel="noopener noreferrer"
className="font-bold mt-4 inline-block bg-yellow-500 text-white py-2 px-4 rounded-lg shadow-md hover:bg-yellow-600 transition"
>
Útvonalterv
</a>
</div>
{nearestRestroom.akadalym === 1 ? (
<TfiWheelchair className="absolute bottom-10 right-10 w-8 h-8" />
) : null}
</div>
{nearestRestroom.akadalym === 1 ? <TfiWheelchair className="absolute bottom-10 right-10 w-8 h-8"/> : ""}
</div>
</div>
);
}
// Default render (before location permission)
return (
<div className="flex flex-col items-center justify-center h-screen bg-yellow-100">
<div className="bg-white p-6 rounded-lg shadow-lg w-80 space-y-4 text-center">
<h2 className="text-xl font-bold">Helyzetmeghatározás</h2>
<p className="text-gray-700">Engedélyezed a helyzetmeghatározást?</p>
<div className="flex justify-center space-x-4">
<button
<button
onClick={handleLocationPermission}
className="px-5 py-2 bg-green-600 text-white font-bold text-lg rounded-lg shadow-md hover:bg-green-700 transition"
>
@@ -145,4 +132,4 @@ export default function LegkozelebbiMosdo() {
</div>
</div>
);
}
}

View File

@@ -1,6 +1,6 @@
export async function mosdokFetch() {
try {
const response = await fetch('http://127.0.0.1:8000/api/mosdok');
const response = await fetch('http://192.168.0.78:8000/api/mosdok');
if (!response.ok) {
throw new Error(`Hiba: ${response.status}`);
}