const initialState = {
isFetching: true,
data: null
};
export default function weather(state = initialState, action){
switch (action.type) {
case "FETCH_WEATHER_DATA":
state.data = action.data
state.isFetching = action.isFetching
return state;
break;
default:
return state;
}
}
const Weather = (props) =>{
const [isFetching, setFetching] = useState(true);
useEffect(()=>{
let lat;
let long;
navigator.geolocation.getCurrentPosition(position =>{
lat = position.coords.latitude+17;
long = position.coords.longitude;
props.onGetWeather(lat,long)
});
setFetching(props.weather.isFetching)
},[])
if(isFetching){
return(
<div id='loading'>
<h1>Loading... {props.weather.error}</h1>
</div>
)
}else{
return(
<React.Fragment>
<React.Fragment>
<h1>{props.weather.data.timezone}</h1>
<div className='weatherWrap'>
<h3>{props.weather.data.currently.temperature}</h3>
<h5>{props.weather.data.currently.summary}</h5>
</div>
</React.Fragment>
</React.Fragment>
)
}
}
const Weather = (props) =>{
useEffect(()=>{
let lat;
let long;
navigator.geolocation.getCurrentPosition(position =>{
lat = position.coords.latitude+17;
long = position.coords.longitude;
props.onGetWeather(lat,long)
});
},[])
if(props.weather.isFetching){
return(
<div id='loading'>
<h1>Loading... {props.weather.error}</h1>
</div>
)
}else{
return(
<React.Fragment>
<React.Fragment>
<h1>{props.weather.data.timezone}</h1>
<div className='weatherWrap'>
<h3>{props.weather.data.currently.temperature}</h3>
<h5>{props.weather.data.currently.summary}</h5>
</div>
</React.Fragment>
</React.Fragment>
)
}
}
export default function authorisation(state = {key: false}, action){
switch (action.type) {
case 'LOGIN_USER_SUCCESS':
return action.key
break;
default:
return state;
}
}
export default connect(
state =>({
success: state.key
}),
export function fetchSuccess(key){
return {
type: 'LOGIN_USER_SUCCESS',
key
}
}
export function authorisation(url, data){
return (dispatch) => {
return fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: new Headers({
'Content-Type': 'application/json'
}),
})
.then(response =>{
if(!response.ok){
throw new Error(response.statusText)
}
return response;
})
.then(response => response.json())
.then(data => dispatch(fetchSuccess(data)))
}
}
Даже очень, но все равно не понимаю как применить
Попробовал уже всем opacity, и осмыслил контекст наложения, пока ничего не меняется