diff --git a/backend/autoszalon.db b/backend/autoszalon.db index d76cce0..41dabc0 100644 Binary files a/backend/autoszalon.db and b/backend/autoszalon.db differ diff --git a/src/App.jsx b/src/App.jsx index f3bd7ca..3c8f5b0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -11,8 +11,40 @@ import UjAutoForm from './components/UjAutoForm' function App() { const [autok, setAutok] = useState([]) + const kezdoAllapot = () => { + fetch("http://localhost:3000/api/autok") + .then(response => response.json()) + .then(json => { + setAutok(json); + }); + }; + + useEffect(() => { + kezdoAllapot() + }, []) + const elemTorles = (elem) => { + const requestOptions = { + method:'Delete' + }; + fetch(`http://localhost:3000/api/autok/${elem.id}`,requestOptions) + .then(response =>response.json()) + .then(data => { + kezdoAllapot(); + }) + } + + const hozzaAdas = (ujAuto) => { + fetch("http://localhost:3000/api/autok", { + method: "POST", + headers: {"Content-Type": "application/json"}, + body: JSON.stringify(ujAuto) + }) + .then(res => res.json) + .then(()=> kezdoAllapot()) + } + return ( <> @@ -27,15 +59,17 @@ function App() { }> + }/> + }> + }> + }> + + {/* 3 alútvonal létrehozása: -összefoglalás (alapértelmezett legyen) -autók listája -új autó hozzáadás */} - - - - ) diff --git a/src/components/AutoKartya.jsx b/src/components/AutoKartya.jsx index 5c87c16..d5d554a 100644 --- a/src/components/AutoKartya.jsx +++ b/src/components/AutoKartya.jsx @@ -6,11 +6,11 @@ const AutoKartya = ({ auto, torles }) => { return (
-
Márka
-
Típus
-

Évjárat - Szín - Uzemanyag

-
Ár: xxxxxxxxxxxx Ft.
- {/* Törlés gomb */} +
Márka: {auto.marka}
+
Típus: {auto.tipus}
+

Évjárat: {auto.evjarat} - Szín:{auto.szin} - Uzemanyag:{auto.uzemanyag}

+
Ár: {auto.ar} Ft.
+
) diff --git a/src/components/AutoLista.jsx b/src/components/AutoLista.jsx index 8ec8888..a2c1083 100644 --- a/src/components/AutoLista.jsx +++ b/src/components/AutoLista.jsx @@ -4,7 +4,9 @@ import AutoKartya from './AutoKartya' const AutoLista = ({autok, torles}) => { return (
- {/* Az autókat megjelenítő komponensek */} + {autok.map(auto => ( + + ))}
) } diff --git a/src/components/FoMenu.jsx b/src/components/FoMenu.jsx index 8f6b61c..5f6e364 100644 --- a/src/components/FoMenu.jsx +++ b/src/components/FoMenu.jsx @@ -5,9 +5,9 @@ const FoMenu = () => { return ( ) diff --git a/src/components/Osszefoglalas.jsx b/src/components/Osszefoglalas.jsx index c021dc5..67a35e5 100644 --- a/src/components/Osszefoglalas.jsx +++ b/src/components/Osszefoglalas.jsx @@ -1,9 +1,18 @@ import React from 'react' -const Osszefoglalas = () => { +const Osszefoglalas = ({autok}) => { + const db = autok.length; + const osszertek = autok.reduce((sum, auto) => sum + Number(auto.ar), 0) + const legrégebbi = Math.min(...autok.map(a => Number(a.evjarat))) +const legújabb = Math.max(...autok.map(a => Number(a.evjarat))) +/*Összefoglalas - egy rövid statisztika tetszőleges formátumban az autók számáról, azok összértékéröl, + a legrégebbi és a legújabb évjáratról.*/ return ( -
Összefoglalas - egy rövid statisztika tetszőleges formátumban az autók számáról, azok összértékéröl, - a legrégebbi és a legújabb évjáratról. +
+

Autók száma: {db}

+

Autók összértéke: {osszertek} Ft

+

legrégebbi autó: {legrégebbi} év

+

Legújabb autó: {legújabb} év

) } diff --git a/src/components/UjAutoForm.jsx b/src/components/UjAutoForm.jsx index 07828ce..40e1065 100644 --- a/src/components/UjAutoForm.jsx +++ b/src/components/UjAutoForm.jsx @@ -1,48 +1,64 @@ -import React from 'react' -import { useState } from 'react' +import React, { useState } from 'react' -const UjAutoForm = ({hozzaad}) => { +const UjAutoForm = ({ hozzaad }) => { - + const [marka, setMarka] = useState("Audi") + const [tipus, setTipus] = useState("") + const [evjarat, setEvjarat] = useState("") + const [szin, setSzin] = useState("") + const [ar, setAr] = useState("") + const [uzemanyag, setUzemanyag] = useState("") + const handleSubmit = (e) => { + e.preventDefault() + + const ujAuto = { marka, tipus, evjarat, szin, ar, uzemanyag } + + hozzaad(ujAuto) + } return (
-
+
- setMarka(e.target.value)} + > + + + + + + + +
- + setTipus(e.target.value)} required + />
- + setEvjarat(e.target.value)} required + />
- + setSzin(e.target.value)} + />
- + setAr(e.target.value)} required + />
- - + + setUzemanyag(e.target.value)} placeholder="benzin, dízel, elektromos stb." + />
-
@@ -51,4 +67,4 @@ const UjAutoForm = ({hozzaad}) => { ) } -export default UjAutoForm \ No newline at end of file +export default UjAutoForm