├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── 404.html
├── images
│ ├── day
│ │ ├── clear.jpg
│ │ ├── clouds.jpg
│ │ ├── fog.jpg
│ │ ├── rain.jpg
│ │ ├── snow.png
│ │ └── thunderstorm.jpg
│ └── night
│ │ ├── clear.jpg
│ │ ├── clouds.jpg
│ │ ├── fog.jpg
│ │ ├── rain.jpg
│ │ ├── snow.png
│ │ └── thunderstorm.jpg
├── index.html
└── readmeImages
│ ├── Screenshot 2024-08-05 233618.png
│ ├── Screenshot 2024-08-06 014316.png
│ └── Screenshot 2024-08-06 014343.png
└── src
├── App.css
├── App.js
├── assests
├── css
│ ├── fonts.css
│ ├── reset.css
│ └── variables.css
├── datas
│ └── citiesName.js
└── fonts
│ └── vazir
│ ├── Vazir-Bold.woff
│ ├── Vazir-Medium.woff2
│ └── Vazir.woff2
├── components
├── ForecastChart
│ ├── ForecastChart.css
│ └── ForecastChart.jsx
├── Header
│ ├── Header.css
│ ├── Header.jsx
│ ├── SearchInput.css
│ └── SearchInput.jsx
├── Loader
│ ├── Loader.css
│ └── Loader.jsx
├── MainWeatherInfo
│ ├── MainWeatherInfo.css
│ └── MainWeatherInfo.jsx
└── MoreWeatherInfo
│ ├── MoreWeatherInfo.css
│ ├── MoreWeatherInfo.jsx
│ ├── MoreWeatherInfoItem.css
│ └── MoreWeatherInfoItem.jsx
├── contexts
└── weatherContext.js
├── hooks
├── useDynamicBackground.js
└── useWeather.js
├── index.css
├── index.js
├── pages
├── forecast
│ ├── Forecast.css
│ └── Forecast.jsx
└── home
│ ├── Home.css
│ └── Home.jsx
└── routes.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [LIVE DEMO](https://parsa-sbg.github.io/weather-app)
3 |
4 | a simple weather website using react js, react router and open weathermap api
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | # Getting Started with Create React App
18 |
19 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
20 |
21 | ## Available Scripts
22 |
23 | In the project directory, you can run:
24 |
25 | ### `npm start`
26 |
27 | Runs the app in the development mode.\
28 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
29 |
30 | The page will reload when you make changes.\
31 | You may also see any lint errors in the console.
32 |
33 | ### `npm test`
34 |
35 | Launches the test runner in the interactive watch mode.\
36 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
37 |
38 | ### `npm run build`
39 |
40 | Builds the app for production to the `build` folder.\
41 | It correctly bundles React in production mode and optimizes the build for the best performance.
42 |
43 | The build is minified and the filenames include the hashes.\
44 | Your app is ready to be deployed!
45 |
46 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
47 |
48 | ### `npm run eject`
49 |
50 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
51 |
52 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
53 |
54 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
55 |
56 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "weather-app",
3 | "version": "0.1.0",
4 | "homepage": "https://parsa-sbg.github.io/weather-app",
5 | "private": true,
6 | "dependencies": {
7 | "@emotion/react": "^11.13.0",
8 | "@emotion/styled": "^11.13.0",
9 | "@mui/material": "^5.16.5",
10 | "@testing-library/jest-dom": "^5.17.0",
11 | "@testing-library/react": "^13.4.0",
12 | "@testing-library/user-event": "^13.5.0",
13 | "gh-pages": "^6.1.1",
14 | "moment": "^2.30.1",
15 | "mui": "^0.0.1",
16 | "react": "^18.3.1",
17 | "react-dom": "^18.3.1",
18 | "react-icons": "^5.2.1",
19 | "react-router-dom": "^6.25.1",
20 | "react-scripts": "5.0.1",
21 | "recharts": "^2.13.0-alpha.4",
22 | "web-vitals": "^2.1.4"
23 | },
24 | "scripts": {
25 | "predeploy": "npm run build",
26 | "deploy": "gh-pages -d build",
27 | "start": "react-scripts start",
28 | "build": "react-scripts build",
29 | "test": "react-scripts test",
30 | "eject": "react-scripts eject"
31 | },
32 | "eslintConfig": {
33 | "extends": [
34 | "react-app",
35 | "react-app/jest"
36 | ]
37 | },
38 | "browserslist": {
39 | "production": [
40 | ">0.2%",
41 | "not dead",
42 | "not op_mini all"
43 | ],
44 | "development": [
45 | "last 1 chrome version",
46 | "last 1 firefox version",
47 | "last 1 safari version"
48 | ]
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Redirecting...
7 |
11 |
12 |
13 | Redirecting...
14 |
15 |
16 |
--------------------------------------------------------------------------------
/public/images/day/clear.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/day/clear.jpg
--------------------------------------------------------------------------------
/public/images/day/clouds.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/day/clouds.jpg
--------------------------------------------------------------------------------
/public/images/day/fog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/day/fog.jpg
--------------------------------------------------------------------------------
/public/images/day/rain.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/day/rain.jpg
--------------------------------------------------------------------------------
/public/images/day/snow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/day/snow.png
--------------------------------------------------------------------------------
/public/images/day/thunderstorm.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/day/thunderstorm.jpg
--------------------------------------------------------------------------------
/public/images/night/clear.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/night/clear.jpg
--------------------------------------------------------------------------------
/public/images/night/clouds.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/night/clouds.jpg
--------------------------------------------------------------------------------
/public/images/night/fog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/night/fog.jpg
--------------------------------------------------------------------------------
/public/images/night/rain.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/night/rain.jpg
--------------------------------------------------------------------------------
/public/images/night/snow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/night/snow.png
--------------------------------------------------------------------------------
/public/images/night/thunderstorm.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/images/night/thunderstorm.jpg
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 | React App
12 |
13 |
14 | You need to enable JavaScript to run this app.
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/public/readmeImages/Screenshot 2024-08-05 233618.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/readmeImages/Screenshot 2024-08-05 233618.png
--------------------------------------------------------------------------------
/public/readmeImages/Screenshot 2024-08-06 014316.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/readmeImages/Screenshot 2024-08-06 014316.png
--------------------------------------------------------------------------------
/public/readmeImages/Screenshot 2024-08-06 014343.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/public/readmeImages/Screenshot 2024-08-06 014343.png
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .app-bg{
2 | background-position: center;
3 | background-repeat: no-repeat;
4 | background-size: cover;
5 | }
6 |
7 | .App{
8 | background-color: #00000060;
9 | color: aliceblue;
10 | min-height: 100vh;
11 | }
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import './App.css';
2 | import Header from './components/Header/Header';
3 | import Container from '@mui/material/Container';
4 | import Routes from './routes';
5 | import { useDynamicBackground } from './hooks/useDynamicBackground';
6 |
7 | function App() {
8 |
9 | const backgrountURL = useDynamicBackground()
10 |
11 | return (
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | );
22 | }
23 |
24 | export default App;
25 |
--------------------------------------------------------------------------------
/src/assests/css/fonts.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'vazir bold';
3 | src: url(../fonts/vazir/Vazir-Bold.woff);
4 | }
5 | @font-face {
6 | font-family: 'vazir';
7 | src: url(../fonts/vazir/Vazir.woff2);
8 | }
9 | @font-face {
10 | font-family: 'vazir md';
11 | src: url(../fonts/vazir/Vazir-Medium.woff2);
12 | }
--------------------------------------------------------------------------------
/src/assests/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/
2 | v2.0 | 20110126
3 | License: none (public domain)
4 | */
5 |
6 | html, body, div, span, applet, object, iframe,
7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
8 | a, abbr, acronym, address, big, cite, code,
9 | del, dfn, em, img, ins, kbd, q, s, samp,
10 | small, strike, strong, sub, sup, tt, var,
11 | b, u, i, center,
12 | dl, dt, dd, ol, ul, li,
13 | fieldset, form, label, legend,
14 | table, caption, tbody, tfoot, thead, tr, th, td,
15 | article, aside, canvas, details, embed,
16 | figure, figcaption, footer, header, hgroup,
17 | menu, nav, output, ruby, section, summary,
18 | time, mark, audio, video {
19 | margin: 0;
20 | padding: 0;
21 | border: 0;
22 | font-size: 100%;
23 | font: inherit;
24 | vertical-align: baseline;
25 | }
26 | /* HTML5 display-role reset for older browsers */
27 | article, aside, details, figcaption, figure,
28 | footer, header, hgroup, menu, nav, section {
29 | display: block;
30 | }
31 | body {
32 | line-height: 1;
33 | }
34 | ol, ul {
35 | list-style: none;
36 | }
37 | blockquote, q {
38 | quotes: none;
39 | }
40 | blockquote:before, blockquote:after,
41 | q:before, q:after {
42 | content: '';
43 | content: none;
44 | }
45 | table {
46 | border-collapse: collapse;
47 | border-spacing: 0;
48 | }
--------------------------------------------------------------------------------
/src/assests/css/variables.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/src/assests/css/variables.css
--------------------------------------------------------------------------------
/src/assests/fonts/vazir/Vazir-Bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/src/assests/fonts/vazir/Vazir-Bold.woff
--------------------------------------------------------------------------------
/src/assests/fonts/vazir/Vazir-Medium.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/src/assests/fonts/vazir/Vazir-Medium.woff2
--------------------------------------------------------------------------------
/src/assests/fonts/vazir/Vazir.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/parsa-sbg/weather-app/5f453f4624bfd097ecb1504b37e834107eaea883/src/assests/fonts/vazir/Vazir.woff2
--------------------------------------------------------------------------------
/src/components/ForecastChart/ForecastChart.css:
--------------------------------------------------------------------------------
1 | .ForecastChart-wrapper{
2 | backdrop-filter: blur(2px);
3 | background-color: #00000016;
4 | border-radius: 2rem;
5 | height: fit-content;
6 | padding: 2rem;
7 | border: 1px solid #fff;
8 | }
9 |
10 | .ForecastChart__title{
11 | text-align: center;
12 | margin-bottom: 1rem;
13 | }
14 |
15 | .ForecastChart {
16 | margin-left: -2rem;
17 | }
--------------------------------------------------------------------------------
/src/components/ForecastChart/ForecastChart.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import './ForecastChart.css'
3 | import { CartesianGrid, Legend, Line, LineChart, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'
4 |
5 |
6 | export default function ForecastChart({ data, date }) {
7 | return (
8 |
9 |
{date}
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | )
25 | }
26 |
--------------------------------------------------------------------------------
/src/components/Header/Header.css:
--------------------------------------------------------------------------------
1 | header {
2 | backdrop-filter: blur(3px);
3 | background-color: rgba(0, 0, 0, 0.338);
4 | border-bottom-left-radius: 2rem;
5 | border-bottom-right-radius: 2rem;
6 | border-bottom: 1px solid #fff;
7 | position: sticky;
8 | z-index: 10;
9 | }
10 |
11 | .header-wrapper{
12 | display: flex;
13 | align-items: center;
14 | justify-content: space-between;
15 | padding: 2rem 0rem;
16 | gap: 1rem;
17 | height: 8rem;
18 | }
19 |
20 | /* start header left */
21 |
22 | .header__left{
23 |
24 | }
25 | .header__logo{
26 |
27 | }
28 | .header__links{
29 | display: flex;
30 | align-items: center;
31 | gap: 2rem;
32 | }
33 | .header__link{
34 | font-size: 2rem;
35 | text-wrap: nowrap;
36 | text-decoration: none;
37 | display: flex;
38 | align-items: center;
39 | color: aliceblue;
40 | font-size: 4rem;
41 | -webkit-tap-highlight-color: transparent;
42 | }
43 |
44 | .header__link.active{
45 | color: rgb(40, 83, 40);
46 | }
47 |
48 | /* end header left */
49 |
50 |
51 |
52 |
53 | /* start header right */
54 |
55 | .header__right{
56 | display: flex;
57 | align-items: center;
58 | }
59 |
60 |
61 |
62 | /* end header right */
63 |
64 |
65 | /* responsive */
66 | @media only screen and (max-width: 500px) {
67 | .header__logo{
68 | width: 5rem;
69 | }
70 | .header__links{
71 | gap: 1rem;
72 | }
73 | .MuiContainer-root{
74 | padding: 0 8px !important;
75 | }
76 | }
--------------------------------------------------------------------------------
/src/components/Header/Header.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import './Header.css'
3 | import { NavLink } from 'react-router-dom'
4 | import { FaHome } from "react-icons/fa";
5 | import { FaCalendarDays } from "react-icons/fa6";
6 | import Container from '@mui/material/Container';
7 | import SearchInput from './SearchInput';
8 |
9 |
10 | export default function Header({ }) {
11 |
12 |
13 | return (
14 |
15 |
16 |
17 |
18 |
19 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | )
36 | }
--------------------------------------------------------------------------------
/src/components/Header/SearchInput.css:
--------------------------------------------------------------------------------
1 | .form {
2 | position: relative;
3 | }
4 |
5 | .input {
6 | border: none;
7 | outline: none;
8 | padding: 1rem .5rem;
9 | font-size: 2rem;
10 | padding-right: 3.5rem;
11 | width: 100%;
12 | background-color: transparent;
13 | color: #cecdcd;
14 | border-left: 2px solid #cecdcd;
15 |
16 | }
17 |
18 | .searchbtn {
19 | padding: 0;
20 | cursor: pointer;
21 | position: absolute;
22 | right: 0;
23 | top: 0;
24 | bottom: 0;
25 | margin: auto;
26 | display: flex;
27 | align-items: center;
28 | justify-content: center;
29 | background-color: transparent;
30 | border: 1px solid #cecdcd;
31 | border-radius: 100%;
32 | width: fit-content;
33 | height: fit-content;
34 | padding: .5rem;
35 | -webkit-tap-highlight-color: transparent;
36 |
37 | }
38 |
39 | .searchbtn-icon {
40 | size: 50;
41 | color: #cecdcd;
42 | }
43 |
44 | .suggestedCities-list {
45 | display: flex;
46 | flex-direction: column;
47 | justify-content: center;
48 | align-items: center;
49 | gap: 1rem;
50 | margin-top: 1rem;
51 | position: absolute;
52 | top: 110%;
53 | width: 100%;
54 | }
55 |
56 | .suggestedCities-item {
57 | width: 80%;
58 | padding: .4rem 1rem;
59 | text-align: center;
60 | background-color: transparent;
61 | background-color: rgb(0, 0, 0);
62 | color: #cecdcd;
63 | border: 1px solid #cecdcd;
64 | border-radius: 2rem;
65 | cursor: pointer;
66 | transition: all 200ms linear;
67 | }
68 |
69 | .suggestedCities-item:hover {
70 | background-color: rgba(50, 46, 46, 0.868);
71 | }
--------------------------------------------------------------------------------
/src/components/Header/SearchInput.jsx:
--------------------------------------------------------------------------------
1 | import './SearchInput.css'
2 | import React, { useEffect, useState } from 'react'
3 | import { useWeather } from '../../hooks/useWeather';
4 | import { CiSearch } from "react-icons/ci";
5 | import {citiesNames} from '../../assests/datas/citiesName'
6 |
7 | export default function SearchInput() {
8 | const [searchedCityname, setsearchedCityName] = useState('')
9 | const [inputValue, setInputValue] = useState('')
10 | const [suggestedCities, setSuggestedCities] = useState([])
11 | const { setCityName } = useWeather()
12 |
13 | const allCities = citiesNames
14 |
15 | useEffect(() => {
16 | searchedCityname && setCityName(searchedCityname)
17 | setInputValue('')
18 | setSuggestedCities([])
19 | }, [searchedCityname])
20 |
21 | useEffect(() => {
22 | suggestedCitiesGenerator()
23 | }, [inputValue])
24 |
25 | const inputChangeHandler = async (e) => {
26 | setInputValue(e.target.value)
27 | }
28 |
29 | const SubmitHandler = (e) => {
30 | e.preventDefault()
31 | setsearchedCityName(inputValue)
32 | }
33 |
34 | const suggestedCitiesGenerator = () => {
35 | if (inputValue.trim()) {
36 | const newSuggestedCities = allCities.filter(city => city.toLowerCase().startsWith(inputValue.toLowerCase())).splice(0, 3)
37 | setSuggestedCities(newSuggestedCities)
38 | } else {
39 | setSuggestedCities([])
40 | }
41 | }
42 |
43 | const suggestedCityClickHandler = (e) => {
44 |
45 | if (searchedCityname == e.target.textContent) {
46 | setCityName(searchedCityname)
47 | setInputValue('')
48 | setSuggestedCities([])
49 | } else {
50 | setsearchedCityName(e.target.textContent)
51 | }
52 | }
53 |
54 |
55 | return (
56 |
71 | )
72 | }
73 |
--------------------------------------------------------------------------------
/src/components/Loader/Loader.css:
--------------------------------------------------------------------------------
1 |
2 | .laoder-wrapper{
3 | position: fixed;
4 | top: 0;
5 | bottom: 0;
6 | right: 0;
7 | left: 0;
8 | height: 100%;
9 | width: 100%;
10 | display: flex;
11 | align-items: center;
12 | justify-content: center;
13 | backdrop-filter: blur(10px);
14 | z-index: 1000;
15 | }
16 |
17 |
18 | .loader {
19 | border: 16px solid #f3f3f3;
20 | border-radius: 50%;
21 | border-top: 16px solid #3498db;
22 | border-bottom: 16px solid #3498db;
23 | width: 120px;
24 | height: 120px;
25 | -webkit-animation: spin 2s linear infinite;
26 | animation: spin 2s linear infinite;
27 | }
28 |
29 | @-webkit-keyframes spin {
30 | 0% { -webkit-transform: rotate(0deg); }
31 | 100% { -webkit-transform: rotate(360deg); }
32 | }
33 |
34 | @keyframes spin {
35 | 0% { transform: rotate(0deg); }
36 | 100% { transform: rotate(360deg); }
37 | }
--------------------------------------------------------------------------------
/src/components/Loader/Loader.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import './Loader.css'
3 |
4 |
5 | export default function Loader() {
6 | return (
7 |
10 | )
11 | }
12 |
--------------------------------------------------------------------------------
/src/components/MainWeatherInfo/MainWeatherInfo.css:
--------------------------------------------------------------------------------
1 | .MainWeatherInfo {
2 | display: flex;
3 | align-items: center;
4 | gap: 1rem;
5 | }
6 |
7 | .MainWeatherInfo__temp {
8 | font-size: 10rem;
9 | }
10 |
11 | .MainWeatherInfo__detail {
12 | display: flex;
13 | flex-direction: column;
14 | align-items: center;
15 | justify-content: center;
16 | text-wrap: nowrap;
17 | }
18 |
19 | .MainWeatherInfo__city-name {
20 | width: 100%;
21 | font-size: 6rem;
22 | text-wrap: wrap;
23 | }
24 |
25 | .MainWeatherInfo__date {
26 | font-size: 2rem;
27 | }
28 |
29 | .MainWeatherInfo__icon {
30 | margin: -2rem;
31 | }
32 |
33 | @media only screen and (max-width: 800px) {
34 | .MainWeatherInfo__temp {
35 | font-size: 8rem;
36 | }
37 |
38 | .MainWeatherInfo__city-name {
39 | font-size: 5rem;
40 | }
41 |
42 | .MainWeatherInfo__icon {
43 | font-size: 5rem;
44 | }
45 | .MainWeatherInfo{
46 | height: 34%;
47 | }
48 | }
49 |
50 | @media only screen and (max-width: 500px) {
51 | .MainWeatherInfo__temp {
52 | font-size: 5rem;
53 | }
54 |
55 | .MainWeatherInfo__city-name {
56 | font-size: 4rem;
57 | }
58 |
59 | .MainWeatherInfo__icon {
60 | font-size: 4rem;
61 | }
62 | .MainWeatherInfo__date {
63 | font-size: 1.8rem;
64 | }
65 | }
--------------------------------------------------------------------------------
/src/components/MainWeatherInfo/MainWeatherInfo.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import './MainWeatherInfo.css'
3 |
4 |
5 | export default function MainWeatherInfo({mainWeatherInfo}) {
6 |
7 | return (
8 |
9 |
{mainWeatherInfo.temp}°
10 |
11 | {mainWeatherInfo.cityName}
12 | {mainWeatherInfo.date}
13 |
14 | {mainWeatherInfo.icon}
15 |
16 | )
17 | }
18 |
--------------------------------------------------------------------------------
/src/components/MoreWeatherInfo/MoreWeatherInfo.css:
--------------------------------------------------------------------------------
1 | .MoreWeatherInfo-wrapper {
2 | display: flex;
3 | align-items: center;
4 | justify-content: end;
5 | width: 100%;
6 | }
7 |
8 | .MoreWeatherInfo {
9 | display: flex;
10 | flex-direction: column;
11 | justify-content: center;
12 | gap: 2.5rem;
13 | font-size: 2.5rem;
14 | width: 100%;
15 | max-width: 35rem;
16 | }
17 |
18 | .MoreWeatherInfo__title {}
19 |
20 | .MoreWeatherInfo__subtitle {}
21 |
22 | .MoreWeatherInfo__body {
23 | display: flex;
24 | flex-direction: column;
25 | gap: 2rem;
26 | }
27 |
28 | @media only screen and (max-width: 800px) {
29 | .MoreWeatherInfo-wrapper {
30 | position: relative;
31 | width: 100%;
32 | justify-content: center;
33 | height: 66%;
34 | backdrop-filter: blur(5px);
35 | }
36 |
37 | .MoreWeatherInfo {
38 | padding: 0 3rem;
39 | }
40 | }
41 |
42 | @media only screen and (max-width: 500px) {}
--------------------------------------------------------------------------------
/src/components/MoreWeatherInfo/MoreWeatherInfo.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import MoreWeatherInfoItem from './MoreWeatherInfoItem'
3 | import './MoreWeatherInfo.css';
4 | import { FaTemperatureThreeQuarters } from "react-icons/fa6";
5 | import { WiHumidity } from "react-icons/wi";
6 | import { BsFillCloudsFill } from "react-icons/bs";
7 | import { FaWind } from "react-icons/fa";
8 |
9 |
10 |
11 |
12 | export default function MoreWeatherInfo({ moreWheaherInfo }) {
13 | return (
14 |
15 |
16 |
17 |
Weather Details...
18 |
19 | } />
20 | } />
21 | } />
22 | } />
23 | } />
24 |
25 |
26 |
27 | )
28 | }
29 |
--------------------------------------------------------------------------------
/src/components/MoreWeatherInfo/MoreWeatherInfoItem.css:
--------------------------------------------------------------------------------
1 | .MoreWeatherInfoItem{
2 | display: flex;
3 | justify-content: space-between;
4 | align-items: center;
5 | font-size: 2rem;
6 | }
7 | .MoreWeatherInfoItem__name{
8 | }
9 | .MoreWeatherInfoItem__right{
10 | display: flex;
11 | align-items: center;
12 | gap: 1rem;
13 | }
14 | .MoreWeatherInfoItem__value{
15 |
16 | }
17 | .MoreWeatherInfoItem__icon{
18 |
19 | }
--------------------------------------------------------------------------------
/src/components/MoreWeatherInfo/MoreWeatherInfoItem.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import './MoreWeatherInfoItem.css'
3 |
4 | export default function MoreWeatherInfoItem({name, value, icon}) {
5 | return (
6 |
7 |
{name}
8 |
9 | {value}
10 | {icon}
11 |
12 |
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/src/contexts/weatherContext.js:
--------------------------------------------------------------------------------
1 | import React, { createContext, useEffect, useRef, useState } from 'react'
2 | import moment from 'moment';
3 |
4 |
5 |
6 | const WeatherContext = createContext(null)
7 |
8 | const WeatherProvider = ({ children }) => {
9 | const [cityName, setCityName] = useState('tehran');
10 | const [isLoading, setIsLoading] = useState(true)
11 |
12 | const weatherData = useRef(null);
13 | const forecast = useRef(null)
14 |
15 | useEffect(() => {
16 |
17 | cityName && fetchWeather(cityName)
18 |
19 | }, [cityName])
20 |
21 | const convertKelvinToCelsius = kelvin => Math.floor(kelvin - 272.15)
22 |
23 | const fetchWeather = async (cityName) => {
24 |
25 | setIsLoading(true)
26 | const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=40846d7c3078163c44131acde6033488`)
27 | const data = await res.json()
28 |
29 | const forecastRes = await fetch(`https://api.openweathermap.org/data/2.5/forecast?q=${cityName}&appid=40846d7c3078163c44131acde6033488&`)
30 | const forecastData = await forecastRes.json()
31 |
32 | res.status == 200 && (weatherData.current = data)
33 | forecastRes.status == 200 && (forecast.current = forecastData)
34 |
35 | setIsLoading(false)
36 | }
37 |
38 | const processForecastData = (forecastData) => {
39 | const forecastList = forecastData?.list
40 |
41 | const groupedByDate = forecastList?.reduce((acc, item) => {
42 | const date = item.dt_txt.split(' ')[0];
43 | if (!acc[date]) {
44 | acc[date] = [];
45 | }
46 | acc[date].push({
47 | time: item.dt_txt.split(' ')[1].slice(0, 5),
48 | temp: convertKelvinToCelsius(item.main.temp),
49 | });
50 | return acc;
51 | }, {});
52 |
53 |
54 | if (groupedByDate) {
55 | const result = Object.entries(groupedByDate).map(([date, hours]) => ({
56 | date,
57 | hours
58 | }));
59 | return result
60 | }
61 | }
62 |
63 |
64 | const mainWeatherInfo = {
65 | mainStatus: weatherData.current?.weather[0].main,
66 | cityName: weatherData.current?.name,
67 | temp: convertKelvinToCelsius(weatherData.current?.main.temp),
68 | date: moment.unix(weatherData.current?.dt).format('h:mm a - dddd'),
69 | icon: ,
70 | }
71 |
72 | const moreWheaherInfo = {
73 | maxTemp: convertKelvinToCelsius(weatherData.current?.main.temp_max),
74 | minTemp: convertKelvinToCelsius(weatherData.current?.main.temp_min),
75 | Humidity: weatherData.current?.main.humidity,
76 | Cloudy: weatherData.current?.clouds.all,
77 | WindSpeed: weatherData.current?.wind.speed
78 |
79 | }
80 |
81 | const weatherForecast = processForecastData(forecast.current)
82 |
83 | const DayOrNight = weatherData.current?.weather[0].icon.slice(2, 3) == 'n' ? 'night' : 'day'
84 | return (
85 |
94 |
95 | {children}
96 |
97 | )
98 | }
99 |
100 | export { WeatherProvider, WeatherContext }
--------------------------------------------------------------------------------
/src/hooks/useDynamicBackground.js:
--------------------------------------------------------------------------------
1 | import { useWeather } from "./useWeather"
2 |
3 | const useDynamicBackground = () => {
4 | const weatherData = useWeather()
5 |
6 | const mainStatus = weatherData.mainWeatherInfo.mainStatus
7 | const { DayOrNight } = weatherData
8 |
9 |
10 | switch (mainStatus?.toLowerCase()) {
11 | case 'drizzle':
12 | return `./images/${DayOrNight}/rain.jpg`
13 |
14 | case 'rain':
15 | return `./images/${DayOrNight}/rain.jpg`
16 |
17 | case 'clear':
18 | return `./images/${DayOrNight}/clear.jpg`
19 |
20 | case 'fog':
21 | return `./images/${DayOrNight}/fog.jpg`
22 |
23 | case 'snow':
24 | return `./images/${DayOrNight}/snow.png`
25 |
26 | case 'Thunderstorm':
27 | return `./images/${DayOrNight}/thunderstorm.jpg`
28 |
29 | case 'clouds':
30 | return `./images/${DayOrNight}/clouds.jpg`
31 |
32 | default:
33 | return `./images/${DayOrNight}/rain.jpg`
34 | }
35 | }
36 | export { useDynamicBackground }
--------------------------------------------------------------------------------
/src/hooks/useWeather.js:
--------------------------------------------------------------------------------
1 | import { useContext } from "react";
2 | import { WeatherContext } from "../contexts/weatherContext";
3 |
4 | const useWeather = () => useContext(WeatherContext)
5 |
6 | export {useWeather}
7 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | @import url(./assests/css/reset.css);
2 | @import url(./assests/css/variables.css);
3 | @import url(./assests/css/fonts.css);
4 |
5 | :root {
6 | font-size: 10px;
7 | }
8 |
9 | *,
10 | *::after,
11 | *::before {
12 | box-sizing: border-box;
13 | }
14 |
15 | body {
16 | font-size: 1.6rem;
17 | font-family: 'vazir';
18 | overflow-x: hidden;
19 | }
20 |
21 | ::-webkit-scrollbar {
22 | width: .5rem;
23 | }
24 |
25 | ::-webkit-scrollbar-thumb {
26 | background-color: #000000a4;
27 | backdrop-filter: blur(10px);
28 | }
29 |
30 | ::-webkit-scrollbar-track{
31 | background-color: gray;
32 | }
33 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 | import { BrowserRouter } from 'react-router-dom';
6 | import { WeatherProvider } from './contexts/weatherContext';
7 |
8 | const root = ReactDOM.createRoot(document.getElementById('root'));
9 | root.render(
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | );
18 |
--------------------------------------------------------------------------------
/src/pages/forecast/Forecast.css:
--------------------------------------------------------------------------------
1 | .forecast{
2 | margin-top: 4rem;
3 | }
4 |
5 | .forecast__cityName{
6 | text-align: center;
7 | font-size: 5rem;
8 | margin-bottom: 2rem;
9 | }
10 |
11 | .forecast__day{
12 |
13 | }
14 |
15 | @media only screen and (max-width:500px) {
16 | .forecast__cityName{
17 | font-size: 3rem;
18 |
19 | }
20 | }
--------------------------------------------------------------------------------
/src/pages/forecast/Forecast.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import './Forecast.css'
3 | import ForecastChart from '../../components/ForecastChart/ForecastChart'
4 | import { Grid } from '@mui/material'
5 | import { useWeather } from '../../hooks/useWeather'
6 | import Loader from '../../components/Loader/Loader'
7 |
8 |
9 |
10 | export default function Forecast() {
11 |
12 | const { weatherForecast, isLoading, mainWeatherInfo } = useWeather()
13 |
14 | return (
15 |
16 | {isLoading && }
17 |
{mainWeatherInfo.cityName} weather forecast
18 |
19 |
20 | {weatherForecast?.map(item => (
21 |
22 |
23 |
24 | ))}
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | )
33 | }
34 |
--------------------------------------------------------------------------------
/src/pages/home/Home.css:
--------------------------------------------------------------------------------
1 | .home{
2 | position: relative;
3 | display: flex;
4 | justify-content: space-between;
5 | height: calc(100vh - 8.1rem);
6 | }
7 |
8 |
9 | @media only screen and (max-width: 800px) {
10 | .home{
11 | flex-direction: column;
12 | align-items: center;
13 | justify-content: center;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/pages/home/Home.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect } from 'react'
2 | import './Home.css'
3 | import MainWeatherInfo from '../../components/MainWeatherInfo/MainWeatherInfo'
4 | import MoreWeatherInfo from '../../components/MoreWeatherInfo/MoreWeatherInfo'
5 | import Loader from '../../components/Loader/Loader'
6 | import { useWeather } from '../../hooks/useWeather'
7 |
8 |
9 | export default function Home() {
10 |
11 | const { isLoading ,mainWeatherInfo, moreWheaherInfo} = useWeather()
12 |
13 | return (
14 |
15 | {isLoading && }
16 |
17 |
18 |
19 | )
20 | }
21 |
--------------------------------------------------------------------------------
/src/routes.js:
--------------------------------------------------------------------------------
1 | import { Route, Routes } from "react-router-dom";
2 | import Home from "./pages/home/Home";
3 | import Forecast from './pages/forecast/Forecast'
4 |
5 | const routes = () => {
6 | return (
7 |
8 | } />
9 | } />
10 | } />
11 |
12 | )
13 | }
14 |
15 | export default routes
--------------------------------------------------------------------------------