add addrainfall on home
This commit is contained in:
@@ -1,24 +1,17 @@
|
|||||||
import React, {useState, useEffect} from "react"
|
import React, {FC, useState, useEffect} from "react"
|
||||||
import Card from "../Card"
|
import Card from "../Card"
|
||||||
import useAxiosTools from "../../hooks/AxiosTools"
|
import useAxiosTools from "../../hooks/AxiosTools"
|
||||||
import {AxiosError} from "axios"
|
import {AxiosError} from "axios"
|
||||||
import {monthlyRainfall} from "../../types"
|
import {monthlyRainfall} from "../../types"
|
||||||
|
|
||||||
const YearRainfall = () => {
|
const YearRainfall: FC<YearRainfallProps> = ({loadedAt}) => {
|
||||||
|
|
||||||
const {errorCatch, errorLabel, setError, axiosGet} = useAxiosTools()
|
const {errorCatch, errorLabel, setError, axiosGet} = useAxiosTools()
|
||||||
const [data, setData] = useState<monthlyRainfall[]>([])
|
const [data, setData] = useState<monthlyRainfall[]>([])
|
||||||
const months = Array(13)
|
|
||||||
.reduce((result, item, index) => {
|
|
||||||
const date = new Date()
|
|
||||||
console.log(item, index, date)
|
|
||||||
return item
|
|
||||||
}, [])
|
|
||||||
console.log(months)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData()
|
fetchData()
|
||||||
}, [])
|
}, [loadedAt])
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -61,3 +54,7 @@ const YearRainfall = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default YearRainfall
|
export default YearRainfall
|
||||||
|
|
||||||
|
interface YearRainfallProps {
|
||||||
|
loadedAt: Date,
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
import React from "react"
|
import React, {useState} from "react"
|
||||||
import useAuthUser from "../hooks/AuthUser"
|
import useAuthUser from "../hooks/AuthUser"
|
||||||
import YearRainfall from "../components/rainfall/YearRainfaill"
|
import YearRainfall from "../components/rainfall/YearRainfaill"
|
||||||
import PageLayout from "../components/PageLayout"
|
import PageLayout from "../components/PageLayout"
|
||||||
|
import AddRainfall from "../components/rainfall/AddRainfall"
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
|
|
||||||
const {authUser} = useAuthUser()
|
const {authUser} = useAuthUser()
|
||||||
|
const [loadedAt, reload] = useState(new Date)
|
||||||
|
|
||||||
return <div>
|
return <div>
|
||||||
{authUser
|
{authUser
|
||||||
? <PageLayout>
|
? <PageLayout>
|
||||||
<YearRainfall />
|
<div className="flex flex-col gap-2">
|
||||||
|
<YearRainfall loadedAt={loadedAt} />
|
||||||
|
|
||||||
|
<AddRainfall reload={reload}/>
|
||||||
|
</div>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
: <div className="px-5 pt-10">
|
: <div className="px-5 pt-10">
|
||||||
<h1 className="text-lg font-bold">Application pour enregistrer sa pluviométrie</h1>
|
<h1 className="text-lg font-bold">Application pour enregistrer sa pluviométrie</h1>
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ const RainfallGraph = () => {
|
|||||||
const {targetRef, dimensions} = useDimension()
|
const {targetRef, dimensions} = useDimension()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setLoading(true)
|
||||||
fetchGraphData()
|
fetchGraphData()
|
||||||
}, [loadedAt, graphDetails])
|
}, [loadedAt, graphDetails])
|
||||||
|
|
||||||
const fetchGraphData = async () => {
|
const fetchGraphData = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
|
||||||
const params = `start=${graphDetails.start_date}&end=${graphDetails.end_date}&period=${graphDetails.period}`
|
const params = `start=${graphDetails.start_date}&end=${graphDetails.end_date}&period=${graphDetails.period}`
|
||||||
const res = await axiosGet(`/api/rainfalls/graph?${params}`)
|
const res = await axiosGet(`/api/rainfalls/graph?${params}`)
|
||||||
setGraphData(res.data)
|
setGraphData(res.data)
|
||||||
@@ -38,27 +38,28 @@ const RainfallGraph = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <PageLayout>
|
return <PageLayout>
|
||||||
<div className="flex flex-wrap justify-between gap-2">
|
|
||||||
<LastFiveMesure loadedAt={loadedAt} />
|
|
||||||
<AddRainfall reload={reload} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{errorLabel()}
|
{errorLabel()}
|
||||||
<form className="mx-5 mb-2 flex flex-wrap gap-2">
|
<form className="mx-5 mb-2 flex flex-wrap gap-2">
|
||||||
<Field name="start_date"
|
<Field name="start_date"
|
||||||
type="date"
|
type="date"
|
||||||
value={graphDetails.start_date}
|
value={graphDetails.start_date}
|
||||||
onChange={e => setGraphDetails({...graphDetails, start_date: (new Date(e.target.value)).toSQLDate()})} />
|
onChange={e => setGraphDetails({
|
||||||
|
...graphDetails,
|
||||||
|
start_date: (new Date(e.target.value)).toSQLDate()
|
||||||
|
})}/>
|
||||||
<Field name="start_date"
|
<Field name="start_date"
|
||||||
type="date"
|
type="date"
|
||||||
value={graphDetails.end_date}
|
value={graphDetails.end_date}
|
||||||
onChange={e => setGraphDetails({...graphDetails, end_date: (new Date(e.target.value)).toSQLDate()})} />
|
onChange={e => setGraphDetails({
|
||||||
|
...graphDetails,
|
||||||
|
end_date: (new Date(e.target.value)).toSQLDate()
|
||||||
|
})}/>
|
||||||
<div className="form-control">
|
<div className="form-control">
|
||||||
<select className={` mt-2 w-full rounded dark:bg-gray-700`}
|
<select className={` mt-2 w-full rounded dark:bg-gray-700`}
|
||||||
value={graphDetails.period}
|
value={graphDetails.period}
|
||||||
onChange={e => setGraphDetails({...graphDetails, period: e.target.value})}>
|
onChange={e => setGraphDetails({...graphDetails, period: e.target.value})}>
|
||||||
<option value="day">Jour</option>
|
<option value="day">Jour</option>
|
||||||
{/* <option value="week">Semaine</option>*/}
|
{/* <option value="week">Semaine</option>*/}
|
||||||
<option value="month">Mois</option>
|
<option value="month">Mois</option>
|
||||||
<option value="year">Année</option>
|
<option value="year">Année</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -68,7 +69,12 @@ const RainfallGraph = () => {
|
|||||||
<RainFallEcharts width={dimensions.width}
|
<RainFallEcharts width={dimensions.width}
|
||||||
height={500}
|
height={500}
|
||||||
data={graphData}
|
data={graphData}
|
||||||
loading={loading} />
|
loading={loading}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap justify-between gap-2">
|
||||||
|
<AddRainfall reload={reload}/>
|
||||||
|
<LastFiveMesure loadedAt={loadedAt}/>
|
||||||
</div>
|
</div>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ const Weather = () => {
|
|||||||
|
|
||||||
{errorLabel()}
|
{errorLabel()}
|
||||||
|
|
||||||
<Card className="flex justify-between">
|
<Card className={`flex justify-between ${loading ? 'animate-pulse' : ''}`}>
|
||||||
<div className="m-2 flex flex-col justify-between">
|
<div className="m-2 flex flex-col justify-between">
|
||||||
<span className="text-6xl">{currentWeather?.main.temp.toFixed()} °C</span>
|
<span className="text-6xl">{currentWeather?.main.temp.toFixed() ?? '--'} °C</span>
|
||||||
<span className="text-secondary dark:text-secondary-ligth">{currentWeather?.weather[0].description}</span>
|
<span className="text-secondary dark:text-secondary-ligth">{currentWeather?.weather[0].description}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-stretch">
|
<div className="flex items-stretch">
|
||||||
@@ -81,8 +81,8 @@ const Weather = () => {
|
|||||||
alt={currentWeather?.weather[0].main} width="120px" />}
|
alt={currentWeather?.weather[0].main} width="120px" />}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<span className="pt-5 text-4xl">{currentWeather?.main.temp_max.toFixed()} <span className="text-2xl">°C</span></span>
|
<span className="pt-5 text-4xl">{currentWeather?.main.temp_max.toFixed() ?? '--'} <span className="text-2xl">°C</span></span>
|
||||||
<span className="mt-2 text-2xl text-secondary dark:text-secondary-ligth">{currentWeather?.main.temp_min.toFixed()} °C</span>
|
<span className="mt-2 text-2xl text-secondary dark:text-secondary-ligth">{currentWeather?.main.temp_min.toFixed() ?? '--'} °C</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user