Refactor: Reorganize state management into atoms and selectors directories
Moved all Recoil atoms to a new 'atoms' directory and selectors to a 'selectors' directory to clarify the project structure and improve maintainability. This change separates concerns by clearly distinguishing between simple state (atoms) and derived state (selectors), facilitating better understanding and scalability of the application's state management.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
// pages/index.js
|
||||
import { useEffect, useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import { loadDataStore } from "../store/selectors/loadDataStore";
|
||||
const MapComponentWithNoSSR = dynamic(
|
||||
() => import("../components/MapComponent"),
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
export default function Home() {
|
||||
const setLoadData = useSetRecoilState(loadDataStore);
|
||||
const [mParam, setMParam] = useState([""]);
|
||||
const [uParam, setUParam] = useState([""]);
|
||||
|
||||
@@ -23,6 +26,13 @@ export default function Home() {
|
||||
const data = await response.json();
|
||||
setLocations(data);
|
||||
};
|
||||
useEffect(() => {
|
||||
setLoadData(async () => {
|
||||
const response = await fetch("/api/readLocations");
|
||||
const data = await response.json();
|
||||
setLocations(data); // Überlegungen für setLocations beachten
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// Funktion, um URL-Parameter zu holen
|
||||
@@ -60,27 +70,7 @@ export default function Home() {
|
||||
console.error("Fehler beim Hinzufügen des Standorts");
|
||||
}
|
||||
};
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
const response = await fetch("/api/addLocation", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log("Erfolg");
|
||||
setFormData({ name: "", longitude: "", latitude: "", type: "" }); // Formular zurücksetzen
|
||||
loadData(); // Daten erneut laden
|
||||
} else {
|
||||
console.error("Fehler beim Speichern der Daten");
|
||||
}
|
||||
};
|
||||
|
||||
const handleChange = (event) => {
|
||||
const { name, value } = event.target;
|
||||
setFormData((prevState) => ({ ...prevState, [name]: value }));
|
||||
};
|
||||
const handleLocationUpdate = (id, newLatitude, newLongitude) => {
|
||||
setLocations((prevLocations) => {
|
||||
return prevLocations.map((location) => {
|
||||
|
||||
Reference in New Issue
Block a user