From 2f2077497ddf8e354d1e5b39be001735b8b162f2 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Mon, 22 Apr 2024 22:23:59 +0200 Subject: [PATCH] add addrainfall on home --- .../js/components/rainfall/YearRainfaill.tsx | 17 +++++------- resources/js/pages/Home.tsx | 10 +++++-- resources/js/pages/Rainfall/RainfallGraph.tsx | 26 ++++++++++++------- resources/js/pages/Weather.tsx | 8 +++--- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/resources/js/components/rainfall/YearRainfaill.tsx b/resources/js/components/rainfall/YearRainfaill.tsx index 988c99f..1da225f 100644 --- a/resources/js/components/rainfall/YearRainfaill.tsx +++ b/resources/js/components/rainfall/YearRainfaill.tsx @@ -1,24 +1,17 @@ -import React, {useState, useEffect} from "react" +import React, {FC, useState, useEffect} from "react" import Card from "../Card" import useAxiosTools from "../../hooks/AxiosTools" import {AxiosError} from "axios" import {monthlyRainfall} from "../../types" -const YearRainfall = () => { +const YearRainfall: FC = ({loadedAt}) => { const {errorCatch, errorLabel, setError, axiosGet} = useAxiosTools() const [data, setData] = useState([]) - const months = Array(13) - .reduce((result, item, index) => { - const date = new Date() - console.log(item, index, date) - return item - }, []) - console.log(months) useEffect(() => { fetchData() - }, []) + }, [loadedAt]) const fetchData = async () => { try { @@ -61,3 +54,7 @@ const YearRainfall = () => { } export default YearRainfall + +interface YearRainfallProps { + loadedAt: Date, +} diff --git a/resources/js/pages/Home.tsx b/resources/js/pages/Home.tsx index 63b5826..ce41194 100644 --- a/resources/js/pages/Home.tsx +++ b/resources/js/pages/Home.tsx @@ -1,16 +1,22 @@ -import React from "react" +import React, {useState} from "react" import useAuthUser from "../hooks/AuthUser" import YearRainfall from "../components/rainfall/YearRainfaill" import PageLayout from "../components/PageLayout" +import AddRainfall from "../components/rainfall/AddRainfall" const Home = () => { const {authUser} = useAuthUser() + const [loadedAt, reload] = useState(new Date) return
{authUser ? - +
+ + + +
:

Application pour enregistrer sa pluviométrie

diff --git a/resources/js/pages/Rainfall/RainfallGraph.tsx b/resources/js/pages/Rainfall/RainfallGraph.tsx index 62e0065..866e7c4 100644 --- a/resources/js/pages/Rainfall/RainfallGraph.tsx +++ b/resources/js/pages/Rainfall/RainfallGraph.tsx @@ -21,12 +21,12 @@ const RainfallGraph = () => { const {targetRef, dimensions} = useDimension() useEffect(() => { + setLoading(true) fetchGraphData() }, [loadedAt, graphDetails]) const fetchGraphData = async () => { try { - setLoading(true) const params = `start=${graphDetails.start_date}&end=${graphDetails.end_date}&period=${graphDetails.period}` const res = await axiosGet(`/api/rainfalls/graph?${params}`) setGraphData(res.data) @@ -38,27 +38,28 @@ const RainfallGraph = () => { } return -
- - -
- {errorLabel()}
setGraphDetails({...graphDetails, start_date: (new Date(e.target.value)).toSQLDate()})} /> + onChange={e => setGraphDetails({ + ...graphDetails, + start_date: (new Date(e.target.value)).toSQLDate() + })}/> setGraphDetails({...graphDetails, end_date: (new Date(e.target.value)).toSQLDate()})} /> + onChange={e => setGraphDetails({ + ...graphDetails, + end_date: (new Date(e.target.value)).toSQLDate() + })}/>
@@ -68,7 +69,12 @@ const RainfallGraph = () => { + loading={loading}/> +
+ +
+ +
} diff --git a/resources/js/pages/Weather.tsx b/resources/js/pages/Weather.tsx index ebfeefd..230491c 100644 --- a/resources/js/pages/Weather.tsx +++ b/resources/js/pages/Weather.tsx @@ -68,9 +68,9 @@ const Weather = () => { {errorLabel()} - +
- {currentWeather?.main.temp.toFixed()} °C + {currentWeather?.main.temp.toFixed() ?? '--'} °C {currentWeather?.weather[0].description}
@@ -81,8 +81,8 @@ const Weather = () => { alt={currentWeather?.weather[0].main} width="120px" />}
- {currentWeather?.main.temp_max.toFixed()} °C - {currentWeather?.main.temp_min.toFixed()} °C + {currentWeather?.main.temp_max.toFixed() ?? '--'} °C + {currentWeather?.main.temp_min.toFixed() ?? '--'} °C