Skip to content

Commit

Permalink
Merge pull request #45 from abhishek622/main
Browse files Browse the repository at this point in the history
#1 final stage update
  • Loading branch information
KejariwalAyush authored Oct 19, 2021
2 parents 89c8411 + 220bcdc commit 23892da
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 11 deletions.
42 changes: 34 additions & 8 deletions weather-app/react-native/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useState } from 'react';
import { ActivityIndicator, StyleSheet, Text, View, SafeAreaView,StatusBar } from 'react-native';
import { ActivityIndicator, StyleSheet, Text, View, SafeAreaView,StatusBar,Alert } from 'react-native';
import SearchBar from './components/SearchBar';
import WeatherUi from './components/WeatherUi';
import * as Location from 'expo-location';

const API_KEY = 'c5212ff223c381bf600ca14a06be152c'

Expand All @@ -10,6 +11,9 @@ export default function App() {

const [weatherData, setWeatherData] = useState(null)
const [loaded, setLoaded] = useState(true)
const [errorMsg, setErrorMsg] = useState('');
// const [location, setLocation ] = useState(null);
const [city, setCity ] = useState();

async function fetchWeather(cityName){
setLoaded(false)
Expand All @@ -28,10 +32,32 @@ export default function App() {
}
}

useEffect(() =>{
fetchWeather('Delhi');
// console.log(weatherData)
},[])
useEffect(() => {
runFunction();
fetchWeather(city);
} , []);

const runFunction = async () => {
let {status} = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
setErrorMsg('Access to Location denied');
}

const location = await Location.getCurrentPositionAsync({});
// setLocation(location)

const place = await Location.reverseGeocodeAsync({
latitude : location.coords.latitude,
longitude : location.coords.longitude
});

let city;
place.find( p => {
city = p.city
setCity(p.city)
});
}


if(!loaded){
return(
Expand All @@ -43,7 +69,7 @@ export default function App() {
return(
<View style={styles.activityContainer}>
<SearchBar fetchWeather={fetchWeather}/>
<Text style={styles.errMsg}>City Not Found!!! Try different city</Text>
<Text style={styles.errMsg}>Something is not right! search city here</Text>
</View>
)
}
Expand All @@ -66,13 +92,13 @@ const styles = StyleSheet.create({
flex: 1,
marginTop: StatusBar.currentHeight || 0,
alignItems:'center',
backgroundColor:'#979797',
backgroundColor:'#f34053',
justifyContent:'center',
},
errMsg:{
fontSize:26,
fontWeight:'bold',
color:'#c21b0c',
color:'#fff',
marginTop:10,
textAlign:'center',
}
Expand Down
15 changes: 15 additions & 0 deletions weather-app/react-native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<img src="https://github.com/abhishek622/projects/blob/main/weather-app/react-native/assets/poster.png"/>

This weather app shows the current temperature in Celcius, wind speed, humidity, pressure (above sea level), and weather description. It also has a search feature from which users can see the weather data of another city. It is an open-source project.

## Project setup

`npm install`

## Start app with

`expo start`

## Screenshot

<img src="https://github.com/abhishek622/projects/blob/main/weather-app/react-native/assets/home_screen.png" height="500"/> <img src="https://github.com/abhishek622/projects/blob/main/weather-app/react-native/assets/search_screen.png" height="500"/>
4 changes: 2 additions & 2 deletions weather-app/react-native/app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"expo": {
"name": "react-native",
"slug": "react-native",
"name": "weather-app",
"slug": "weather-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
Expand Down
Binary file modified weather-app/react-native/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather-app/react-native/assets/home_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified weather-app/react-native/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather-app/react-native/assets/poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified weather-app/react-native/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions weather-app/react-native/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion weather-app/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-web": "~0.13.12"
"react-native-web": "~0.13.12",
"expo-location": "~12.1.2"
},
"devDependencies": {
"@babel/core": "^7.9.0"
Expand Down

0 comments on commit 23892da

Please sign in to comment.