Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"city": "^1.0.4",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove any dependency that you are not using

there something dependencies hell, try to read

"country-state-city": "^2.1.0",
"google-maps-react": "^2.0.6",
"moment": "^2.29.1",
"openweather-apis": "^4.4.1",
"react": "^17.0.2",
"react-country-region-selector": "^3.1.0",
"react-datetime": "^3.0.4",
"react-dom": "^17.0.2",
"react-open-weather": "^1.1.5",
"react-scripts": "4.0.3",
"react-select-cities": "^2.0.0",
"weather-icons-react": "^1.2.0",
"web-vitals": "^1.1.2"
},
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.App {
text-align: center;
background-color: #282c34;
font-size: calc(10px + 2vmin);
color: white;
min-height: 100vh;



Comment on lines +7 to +9
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove those extra lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there an extension called prettier, try to use

}

.App-logo {
Expand Down
24 changes: 8 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import logo from './logo.svg';
import './App.css';

import Inputcity from './component/Inputcity';
// import Weather from './component/Weather';
//import Weatherrr from './component/Weatherrr';
// import Wether from './component/Wether';
Comment on lines +3 to +5
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't leave commented code in your prod

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and everywhere in your code

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
{/* <Wether /> */}
{/* <Weather /> */}
{/* <Weatherrr latt='29' long='44' /> */}
<Inputcity />
</div>
);
}
Expand Down
47 changes: 47 additions & 0 deletions src/component/Inputcity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react'
import Time from './Time'
import Weatherrr from './Weatherrr'
const weather = require('openweather-apis');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you use import here?

Suggested change
const weather = require('openweather-apis');
import weather from 'openweather-apis';


function Inputcity() {
const [cooord, setcooord] = useState({ lati: '51.5085', long: '-0.1257', cityy: 'London' })
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing it like cooord is so confusing
try to call it something like weatherCoord

const [city, setcity] = useState('London')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have a typo here

Suggested change
const [city, setcity] = useState('London')
const [city, setCity] = useState('London')

and maybe you can make it like this

Suggested change
const [city, setcity] = useState('London')
const [cityInput, setCityInput] = useState('London')

const submit = () => {
weather.setLang('en');
weather.setCity(`${city}`);
weather.setUnits('metric');
weather.setAPPID('f7d454f5834522dcb92bcf5d38a1db14');
weather.getAllWeather(function (err, info) {
if (err) {
alert('Input a valid City')
}
Comment on lines +15 to +17
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error could be not just an invalid city, so you have to think about them all

else {
setcooord({ lati: info.coord.lat, long: info.coord.lon, cityy: info.name })
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the city here is hard coded, you should make it variable
it's also bad named, try to use a different name

}
Comment on lines +15 to +20
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (err) {
alert('Input a valid City')
}
else {
setcooord({ lati: info.coord.lat, long: info.coord.lon, cityy: info.name })
}
if (err) {
return alert('Input a valid City')
}
setcooord({ lati: info.coord.lat, long: info.coord.lon, cityy: info.name })


});
}

const loctate = () => {
navigator.geolocation.getCurrentPosition(function (position) {
setcooord({ lati: position.coords.latitude, long: position.coords.longitude, cityy: 'Mosul' })
});

}
const cityhandler = (event) => {
setcity(event.target.value)
}
return (
<div>
<div>
<input type='text' value={city} onChange={cityhandler} autoFocus />
<button onClick={submit}>OK</button>
<button onClick={loctate}>Loctate My Location</button>
Comment on lines +37 to +39
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to activate the submit on enter

</div>
<Time />
<Weatherrr lat={cooord.lati} long={cooord.long} cityName={cooord.cityy} />
</div>
)
}

export default Inputcity
42 changes: 42 additions & 0 deletions src/component/Listing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { Component } from 'react';


class Listing extends Component {

constructor(props) {
super(props)
this.state = {
records: []
}
}

componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(records => {
this.setState({
records: records
})
})
.catch(error => console.log(error))
}

renderListing() {
let recordList = []
this.state.records.map(record => {
return recordList.push(<li key={record.id}>{record.name}</li>)
})

return recordList;
}

render() {
return (
<ul>
{this.renderListing()}
</ul>
);
}
}

export default Listing;
23 changes: 23 additions & 0 deletions src/component/Time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useState, useEffect } from 'react'
import moment from 'moment'

function Time() {
const [time, settime] = useState(moment().format('MMMM Do YYYY, h:mm:ss a'))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [time, settime] = useState(moment().format('MMMM Do YYYY, h:mm:ss a'))
const [time, setTime] = useState(moment().format('MMMM Do YYYY, h:mm:ss a'))


const hanleTime = () => {
settime(moment().format('MMMM Do YYYY, h:mm:ss a'))
}
useEffect(() => {
const Timer = setInterval(hanleTime, 1000);
return () => {
clearInterval(Timer)
}
}, [])
return (
<div>
{time}
</div>
)
}

export default Time
26 changes: 26 additions & 0 deletions src/component/Weatherrr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ReactWeather, { useOpenWeather } from 'react-open-weather';
import React from 'react'


const Weatherrr = (props) => {
const { data, isLoading, errorMessage } = useOpenWeather({
key: 'f7d454f5834522dcb92bcf5d38a1db14',
lat: `${props.lat}`, //lat
lon: `${props.long}`, //lon
Comment on lines +8 to +9
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lat: `${props.lat}`, //lat
lon: `${props.long}`, //lon
lat: props.lat, //lat
lon: props.long, //lon

lang: 'en',
unit: 'metric', // values are (metric, standard, imperial)
});
return (
<ReactWeather
isLoading={isLoading}
errorMessage={errorMessage}
data={data}
lang="en"
locationLabel={props.cityName} // town
unitsLabels={{ temperature: 'C', windSpeed: 'Km/h' }
}
showForecast
/>
);
};
export default Weatherrr