From 53275cf0d78dfe6cf14e16ad326bc210e288d91e Mon Sep 17 00:00:00 2001 From: jeremy Date: Tue, 3 Dec 2024 15:36:57 +0100 Subject: [PATCH 1/2] first push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Noé Lecointe --- .gitignore | 1 + frontend/src/App.jsx | 4 ++- frontend/src/WeatherCard.css | 35 +++++++++++++++++++++++++++ frontend/src/WeatherCard.jsx | 47 ++++++++++++++++++++++++++++++++++++ package-lock.json | 6 +++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 frontend/src/WeatherCard.css create mode 100644 frontend/src/WeatherCard.jsx create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index e1d6bc1..414be11 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -5,6 +5,7 @@ import './App.css' import DaySelector from './DaySelector'; import Header from './Header' import TabMeteo from './TabMeteo' +import WeatherCard from './WeatherCard'; function App() { @@ -60,7 +61,8 @@ function App() { return ( <>
- + + ) diff --git a/frontend/src/WeatherCard.css b/frontend/src/WeatherCard.css new file mode 100644 index 0000000..0d2ae5a --- /dev/null +++ b/frontend/src/WeatherCard.css @@ -0,0 +1,35 @@ +.card { + padding: 1.5rem; + border-radius: 10px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + text-align: center; + transition: transform 0.2s ease-in-out; + } + + .weather-grid { + display: grid; + grid-template-columns: repeat(2, 1fr); /* Deux colonnes */ + gap: 1rem; /* Espacement entre les éléments */ + margin-top: 1rem; + } + + .grid-item { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 0.5rem; + background-color: rgba(255, 255, 255, 0.5); + border-radius: 8px; + } + + .label { + font-weight: bold; + margin-bottom: 0.5rem; + font-size: 1rem; + } + + .grid-item span { + font-size: 1.1rem; + } + \ No newline at end of file diff --git a/frontend/src/WeatherCard.jsx b/frontend/src/WeatherCard.jsx new file mode 100644 index 0000000..038070f --- /dev/null +++ b/frontend/src/WeatherCard.jsx @@ -0,0 +1,47 @@ +import dayjs from 'dayjs'; +import relativeTime from 'dayjs/plugin/relativeTime'; +import 'dayjs/locale/fr'; +import './WeatherCard.css'; + +dayjs.extend(relativeTime); +dayjs.locale('fr'); + +const WeatherCard = ({ data }) => { + const temperatureString = data?.meteo?.temperature; + const temperature = temperatureString ? parseInt(temperatureString.split("°")[0], 10) : null; + + const cardStyle = { + backgroundColor: temperature !== null + ? temperature > 15 + ? "#ff8c00" + : temperature < 10 + ? "#1e90ff" + : "#87ceeb" + : "#ffffff", + }; + + return ( +
+
+
+ Température: + {temperature !== null ? `${temperature}°C` : "Non disponible"} +
+
+ Précipitation: + {data?.meteo?.precipitation ?? "Non disponible"} +
+
+ Humidité: + {data?.meteo?.humidity ?? "Non disponible"} +
+
+ Vent: + {data?.meteo?.wind ?? "Non disponible"} +
+
+
+ ); +}; + +export default WeatherCard; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9b99c1a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "EcoMeteo", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} From a21f608c47eec7453a82c1d5a3cdb51947f23119 Mon Sep 17 00:00:00 2001 From: jeremy Date: Tue, 3 Dec 2024 16:30:23 +0100 Subject: [PATCH 2/2] New UI --- frontend/src/App.css | 49 +++++++---------------- frontend/src/App.jsx | 76 ++++++++++++++++++------------------ frontend/src/Header.css | 48 +++++++++++++++++++++++ frontend/src/Header.jsx | 47 +++++++++++----------- frontend/src/WeatherCard.css | 58 ++++++++++++++++++--------- frontend/src/WeatherCard.jsx | 2 +- 6 files changed, 164 insertions(+), 116 deletions(-) diff --git a/frontend/src/App.css b/frontend/src/App.css index 0b9b146..77b73ad 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -1,40 +1,19 @@ +:root { + --primary-color: #2c3e50; + --secondary-color: #61dafb; + --background-color: #f9f9f9; + --card-background: #ffffff; + --text-color: #34495e; + --shadow-color: rgba(0, 0, 0, 0.1); +} + #root { margin: 0 auto; text-align: center; + max-width: 1200px; + padding: 1rem; + background-color: var(--background-color); + border-radius: 10px; + box-shadow: 0 4px 6px var(--shadow-color); } -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 414be11..2da39bb 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,36 +1,30 @@ -import { useState, useEffect } from 'react' -// import reactLogo from './assets/react.svg' -// import viteLogo from '/vite.svg' -import './App.css' +import { useState, useEffect } from 'react'; +import './App.css'; import DaySelector from './DaySelector'; -import Header from './Header' -import TabMeteo from './TabMeteo' +import Header from './Header'; import WeatherCard from './WeatherCard'; function App() { - const [data, setData] = useState({}); const [cities, setCities] = useState([]); - const [selectedCity, setSelectedCity] = useState('Paris'); const [selectedDate, setSelectedDate] = useState("2024-10-08"); useEffect(() => { - console.log(selectedCity, selectedDate); - fetch('http://localhost:5984/ecometeo/_find', { - method: 'POST', - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - selector: { city: selectedCity, "meteo.date" : selectedDate }, - limit: 1 - }) - }) - .then(x => x.json()) - .then(data => { - setData(data.docs[0]); + fetch('http://localhost:5984/ecometeo/_find', { + method: 'POST', + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + selector: { city: selectedCity, "meteo.date": selectedDate }, + limit: 1 }) + }) + .then((x) => x.json()) + .then((data) => { + setData(data.docs[0]); + }); }, [selectedCity, selectedDate]); useEffect(() => { @@ -38,34 +32,40 @@ function App() { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - selector: { "meteo.date" : selectedDate }, + selector: { "meteo.date": selectedDate }, fields: ["city"], - limit: 1000000, // On veut tous les résultats (Ajout futur d'une table contenant une liste des villes) + limit: 1000000 }) - }) - .then(x => x.json()) - .then(data => { - const uniqueCities = [...new Set(data.docs.map(doc => doc.city))]; - setCities(uniqueCities); }) + .then((x) => x.json()) + .then((data) => { + const uniqueCities = [...new Set(data.docs.map((doc) => doc.city))]; + setCities(uniqueCities); + }); }, []); - const handleCity = (city) => { - setSelectedCity(city); + setSelectedCity(city); }; + const handleDate = (date) => { - setSelectedDate(date); + setSelectedDate(date); }; return ( - <> -
- - - - - ) +
+
+
+ + +
+
+ ); } -export default App +export default App; diff --git a/frontend/src/Header.css b/frontend/src/Header.css index e69de29..a2e8f5c 100644 --- a/frontend/src/Header.css +++ b/frontend/src/Header.css @@ -0,0 +1,48 @@ +.header-container { + display: flex; + align-items: center; + justify-content: space-between; + padding: 1rem 2rem; + background-color: #f4f4f4; /* Couleur de fond subtile */ + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Ombre douce */ + border-radius: 10px; +} + +.select-container { + flex: 1; + max-width: 300px; /* Limite la largeur du menu déroulant */ +} + +.select { + font-size: 1rem; +} + +.logo-container { + flex: 1; + text-align: center; +} + +.logo-container h2 { + font-family: 'Roboto', sans-serif; + font-size: 1.8rem; + color: #2c3e50; /* Texte élégant */ + margin: 0; +} + +.info-container { + flex: 1; + text-align: right; +} + +.city-name { + font-size: 1.2rem; + font-weight: bold; + margin: 0; + color: #34495e; +} + +.date { + font-size: 1rem; + margin: 0; + color: #7f8c8d; +} diff --git a/frontend/src/Header.jsx b/frontend/src/Header.jsx index 2de2a92..70fcf27 100644 --- a/frontend/src/Header.jsx +++ b/frontend/src/Header.jsx @@ -1,36 +1,37 @@ import Select from 'react-select'; import 'dayjs/locale/fr' +import './Header.css' function Header({ cities, ville, cityChange, selectedDate }) { - let options; + const options = cities?.map((city) => ({ value: city, label: city })) || []; - if (cities && cities[0]) { - options = cities.map((city) => ({ value: city, label: city })) - } - - const defaultValue = options && options.find(city => city.value === city); + const defaultValue = options.find((option) => option.value === ville); const handleChange = (selectedOption) => { - cityChange(selectedOption.value); - }; + cityChange(selectedOption.value); + }; const formattedDate = new Date(selectedDate).toLocaleDateString('fr-FR', { day: 'numeric', month: 'long' }); - return ( -
- + +
+

Éco Météo

+
+
+

{ville || 'Ville non sélectionnée'}

+

{formattedDate}

-
- ) +
+ ); } -export default Header \ No newline at end of file +export default Header; diff --git a/frontend/src/WeatherCard.css b/frontend/src/WeatherCard.css index 0d2ae5a..1b480ab 100644 --- a/frontend/src/WeatherCard.css +++ b/frontend/src/WeatherCard.css @@ -1,35 +1,55 @@ -.card { - padding: 1.5rem; +#WeatherCard { + background-color: var(--card-background, #ffffff); border-radius: 10px; - box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); - text-align: center; - transition: transform 0.2s ease-in-out; + padding: 2em; + box-shadow: 0 4px 6px var(--shadow-color, rgba(0, 0, 0, 0.1)); + margin: 1.5rem 0; + width: 100%; + max-width: 100%; + text-align: left; + transition: transform 300ms, box-shadow 300ms; + overflow: hidden; } - .weather-grid { + .grid { display: grid; - grid-template-columns: repeat(2, 1fr); /* Deux colonnes */ - gap: 1rem; /* Espacement entre les éléments */ - margin-top: 1rem; + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + gap: 1.5rem; + font-size: 1.1rem; + color: var(--text-color, #333); } .grid-item { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - padding: 0.5rem; - background-color: rgba(255, 255, 255, 0.5); + background-color: #f7f7f7; + padding: 1.5em; border-radius: 8px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + transition: background-color 300ms ease; } - .label { + .grid-item .label { font-weight: bold; - margin-bottom: 0.5rem; - font-size: 1rem; + color: var(--primary-color, #0077cc); + margin-bottom: 0.5em; + display: block; } .grid-item span { - font-size: 1.1rem; + font-size: 1.2rem; + color: #333; + } + + @media (max-width: 768px) { + #WeatherCard { + padding: 1.5em; + } + + .grid { + grid-template-columns: 1fr; + } + + .grid-item { + padding: 1.2em; + } } \ No newline at end of file diff --git a/frontend/src/WeatherCard.jsx b/frontend/src/WeatherCard.jsx index 038070f..669f6a9 100644 --- a/frontend/src/WeatherCard.jsx +++ b/frontend/src/WeatherCard.jsx @@ -21,7 +21,7 @@ const WeatherCard = ({ data }) => { }; return ( -
+
Température: