Skip to content

Commit

Permalink
Merge pull request #3 from SteveLabrinos/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
SteveLabrinos authored Feb 14, 2021
2 parents 4a090d8 + 376158f commit e55651d
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .eslintcache

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions .idea/workspace.xml

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

1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="icon" href="%PUBLIC_URL%/app-favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="author" content="Steve Labrinos">
<meta
name="description"
content="Weather Application by MSc Information Systems"
Expand Down
5 changes: 5 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "logo512.png",
"type": "image/png",
Expand Down
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ function App() {
<Redirect to="/" />
</Switch> :
<Switch>
<Route path="/collection/:cityName" render={props => <CityConditions {...props} />} />
<Route path="/collection" render={props => <Collections {...props} />} />
<Route path="/search" render={props => <SearchCities {...props} />} />
<Route path="/auth/sign-in" render={props => <SignIn {...props} />} />
<Route path="/auth/sign-up" render={props => <SignUp {...props} />} />
Expand Down
2 changes: 1 addition & 1 deletion src/axios-weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import axios from 'axios';
*/

const instance = axios.create({
baseURL: 'https://msc-ais-weather:9000/'
baseURL: 'https://weather.msc-ais.site/'
});

export default instance;
6 changes: 6 additions & 0 deletions src/components/CityConditions/CityConditions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Fragment, useCallback, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router';
import { Redirect } from "react-router-dom";

import Cockpit from '../UI/Cockpit/Cockpit';
import { fetchInputCityConditions, setCurrentToDisplay, setForecastToDisplay } from '../../store/actions';
Expand All @@ -23,6 +24,7 @@ const CityConditions = () => {
// selectors
const { city, loading, forecastConditions, conditionsFetched, conditionsError,
displayingConditions } = useSelector(state => state.search);
const token = useSelector(state => state.auth.token);

const onInputCityConditions =useCallback(() => {
dispatch(fetchInputCityConditions(cityName));
Expand All @@ -45,6 +47,9 @@ const CityConditions = () => {
}
};

const authRedirect = !token ?
<Redirect to="/" /> : null;

const wConditions = conditionsFetched ?
<WeatherConditions
city={city}
Expand All @@ -63,6 +68,7 @@ const CityConditions = () => {
return (
<Fragment>
<Cockpit title="Συνθήκες Πόλης" />
{authRedirect}
{wConditions}
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const footerContent = props => {
Ακολουθήστε μας:
</Typography>
<Link
href="https://github.com/orgs/MSc-AIS/projects/1"
href="https://github.com/MSc-AIS"
target="_blank"
rel="noreferrer">
<GitHubIcon className={classes.Icon}/>
Expand Down
28 changes: 15 additions & 13 deletions src/components/Naviagation/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ const useStyles = makeStyles((theme) => ({
},
img: {
height: 80,
textAlign: 'center'
textAlign: 'center',
flex: 2
},
logoStyle: {
display: 'flex'
}
}));


Expand All @@ -42,8 +46,15 @@ const Navbar = props => {
<Toolbar className={classes.toolbar} >
<CssBaseline />
<Grid container spacing={2} justify="space-between" alignItems="center">
<Hidden mdUp>
<Grid item xs={1}>
<Hidden smDown>
<Grid item md={3} lg={4}>
<Typography variant="h5" component="h2" className={classes.title}>
AIS Weather
</Typography>
</Grid>
</Hidden>
<Grid item xs={11} md={3} lg={4} className={classes.logoStyle}>
<Hidden mdUp>
<IconButton
edge="start"
className={classes.menuButton}
Expand All @@ -52,16 +63,7 @@ const Navbar = props => {
onClick={props.toggleDrawer}>
<MenuIcon />
</IconButton>
</Grid>
</Hidden>
<Hidden smDown>
<Grid item md={3} lg={4}>
<Typography variant="h5" component="h2" className={classes.title}>
AIS Weather
</Typography>
</Grid>
</Hidden>
<Grid item xs={11} md={3} lg={4}>
</Hidden>
<Typography component="div" className={classes.img}>
<Logo logoType="appLogo" />
</Typography>
Expand Down
9 changes: 4 additions & 5 deletions src/components/Naviagation/SideDrawer/SideDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import Backdrop from '../../UI/Backdrop/Backdrop';
* @author Stavros Labrinos [stalab at linuxmail.org] on 28/01/21.
*/

const sideDrawer = ( props ) => {
const attachedClasses = props.open ? [classes.SideDrawer, classes.Open] : [classes.SideDrawer, classes.Close];
const sideDrawer = ({ open, closed }) => {
const attachedClasses = open ? [classes.SideDrawer, classes.Open] : [classes.SideDrawer, classes.Close];

return (
<Fragment>
<Backdrop show={props.open} clicked={props.closed}/>
<div className={attachedClasses.join(' ')} onClick={props.closed}>
<Backdrop show={open} clicked={closed}/>
<div className={attachedClasses.join(' ')} onClick={closed}>
<div className={classes.Logo}>
<Logo logoType="appLogo"/>
</div>
<nav>
<NavigationItems />
{/*<NavigationItems isAuthenticated={props.isAuth} />*/}
</nav>
</div>
</Fragment>
Expand Down
3 changes: 2 additions & 1 deletion src/components/UI/Cockpit/Cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import classes from './Cockpit.module.css';
const cockpit = props => {

return (
// temp disable cockpit title
<Hidden mdUp>
<Typography className={classes.Title}
variant="h5"
component="h2"
style={{ marginBottom: '2rem' }}
id="back-to-top-anchor"
color="textPrimary">
{props.title}
{/*{props.title}*/}
</Typography>
</Hidden>
);
Expand Down
20 changes: 10 additions & 10 deletions src/components/UI/Cockpit/Cockpit.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ div .Title {
position: relative;
}

.Title::after {
position: absolute;
content: "";
height: 6px;
width: 15%;
max-width: 60px;
bottom: -16px;
background: #116149;
left: 0;
}
/*.Title::after {*/
/* position: absolute;*/
/* content: "";*/
/* height: 6px;*/
/* width: 15%;*/
/* max-width: 60px;*/
/* bottom: -16px;*/
/* background: #116149;*/
/* left: 0;*/
/*}*/
15 changes: 13 additions & 2 deletions src/components/WeatherConditions/WeatherConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,26 @@ const WeatherConditions = props => {
const prevWeatherId = usePrevious({ weatherId });

useEffect(() => {

if(prevWeatherId && prevWeatherId.weatherId !== weatherId) {
setTemperature({
...temperature,
// ...temperature,
points: props.display.temperatureConditions.temperature ?
props.display.temperatureConditions.temperature: 1,
feelsLike: feelsLike ? feelsLike: 1,
min: minTemperature,
max: maxTemperature,
measurement: 'celsius'
});
}
}, [weatherId, temperature, prevWeatherId, minTemperature, maxTemperature]);
}, [
weatherId,
props.display.temperatureConditions.temperature,
feelsLike,
// temperature,
prevWeatherId,
minTemperature,
maxTemperature]);

return (
<Card className={classes.card}>
Expand Down
35 changes: 24 additions & 11 deletions src/containers/Collections/Collections.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { Fragment, useEffect, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router';
import { Redirect } from 'react-router-dom';

import axios from '../../axios-weather';
import withErrorHandler from '../../hoc/withErrorHandler/withErrorHandler';
import { fetchCitiesCollection, deleteCity } from '../../store/actions';
import Cockpit from '../../components/UI/Cockpit/Cockpit';
import City from '../../components/City/City';
import LoadingProgress from '../../components/UI/LoadingProgress/LoadingProgress';
import { Grid, makeStyles} from '@material-ui/core';
import { Grid, Typography, makeStyles} from '@material-ui/core';

/**
* @returns {JSX.Element}
* @author Stavros Labrinos [stalab at linuxmail.org] on 1/02/21.
*/

const useStyles = makeStyles(theme => ({
root: {
containerStyle: {
marginBottom: theme.spacing(2),
marginTop: theme.spacing(2)
}
},
}));

const Collections = () => {
Expand Down Expand Up @@ -51,20 +52,32 @@ const Collections = () => {
dispatch(deleteCity(cityId, token));
}, [dispatch, token]);

const authRedirect = !token ?
<Redirect to="/" /> : null;

const cities = loading ?
<LoadingProgress /> :
collection.map(city => (
<Grid item xs={12} sm={6} md={4} key={city.id}>
<City {...city}
showDetails={handleShowDetails}
deleteCity={handleDeleteCity} />
</Grid>
));
collection.length > 0?
collection.map(city => (
<Grid item xs={12} sm={6} md={4} key={city.id}>
<City {...city}
showDetails={handleShowDetails}
deleteCity={handleDeleteCity} />
</Grid>
)) :
<Typography
variant="h5"
component="p"
color="textSecondary">
Η συλλογή πόλεων είναι κενή. Μπορείτε να προσθέτε πόλεις στη συλλογή
σας από το μενού «Αναζήτηση»
</Typography>;

return (
<Fragment>
<Cockpit title="Συλλογές Πόλεων" />
<Grid container spacing={2} justify="center" className={classes.root} >
{authRedirect}
<Grid container spacing={2} justify="center" className={classes.containerStyle} >
{cities}
</Grid>
</Fragment>
Expand Down
29 changes: 18 additions & 11 deletions src/containers/CurrentPosition/CurrentPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ const CurrentPosition = () => {
dispatch(actions.fetchCity());
}, [dispatch]);

const onInitWeatherConditions = useCallback((city) => {
dispatch(actions.fetchConditions(city));
const onInitWeatherConditions = useCallback(() => {
dispatch(actions.fetchConditions());
}, [dispatch]);


// changed useEffect to handle ip location from backend Steve Labrinos 6/2/21
useEffect(() => {
// get city from IP for new sessions
if (!city) {
// if (!city) {
// get city from public API action
onInitCity();
// onInitCity();
// the api may return null as success response. Checking for city again
} else if (!conditionsFetched && city) {
// } else if (!conditionsFetched && city) {
// get weather condition from backend action
onInitWeatherConditions(city.name);
}
}, [city, onInitCity, onInitWeatherConditions, conditionsFetched]);
if (!conditionsFetched) {
onInitWeatherConditions();
}
// }
}, [
// city,
onInitCity,
onInitWeatherConditions,
conditionsFetched]);


const handleDisplayingConditions = day => {
Expand All @@ -65,10 +71,11 @@ const CurrentPosition = () => {
<Typography variant="h5" color="error">
<ErrorOutlineIcon style={{ fontSize: 22, paddingRight: 12 }}/>
Δεν είναι δυνατή η λήψη της τρέχουσας τοποθεσίας. Προσπαθήστε αργότερα
</Typography> : <LoadingProgress /> :
null;
</Typography> :
null : null;

const wConditions = conditionsFetched ?
// <p>test</p> :
<WeatherConditions
city={city}
weatherId={displayingConditions.id}
Expand Down
Loading

0 comments on commit e55651d

Please sign in to comment.