Skip to content

Commit

Permalink
Added viewport height styling to the aside element when there is an e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
hmdNetizen committed Jul 4, 2021
1 parent 52815ca commit 7c30091
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/components/layouts/MainContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const MainContents: React.FC = () => {
const [openSearch, setOpenSearch] = useState(false);
const { fetchWeatherData, getLocationPosition } = useActions();

const { loading, woeid, coords } = useTypedSelector((state) => state.weather);
const { loading, woeid, coords, error } = useTypedSelector(
(state) => state.weather
);

useEffect(() => {
if (coords) {
Expand All @@ -28,7 +30,7 @@ const MainContents: React.FC = () => {
<Spinner />
) : (
<main className="main">
<aside className="aside">
<aside className={error ? "aside aside__error" : "aside"}>
{!openSearch ? (
<AsideContent
setOpenSearch={setOpenSearch}
Expand Down
5 changes: 5 additions & 0 deletions src/sass/index.css

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

2 changes: 1 addition & 1 deletion src/sass/index.css.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/sass/layout/_aside.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
height: 100%;
}

&__error {
height: 100vh;
}

&__background {
max-width: 75em;
position: absolute;
Expand Down
2 changes: 1 addition & 1 deletion src/sass/layout/_main.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.main {
display: grid;
grid-template-columns: 1fr 2fr;
// height: 100vh;
height: 100%;
}
15 changes: 11 additions & 4 deletions src/store/action-creators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,23 @@ export const getLocationPosition =
export const getCurrentLocation = () => (dispatch: Dispatch) => {
const geolocation = navigator.geolocation;
geolocation.getCurrentPosition(
(position) => {
async (position) => {
console.log(position);

const { latitude, longitude } = position.coords;

const { data } = await axios.get(
`${BASE_URL}/search/?lattlong=${latitude},${longitude}`
);

dispatch({
type: ActionTypes.GET_CURRENT_LOCATION_COORDINATES,
payload: position.coords,
type: ActionTypes.GET_CURRENT_LOCATION_POSITION,
payload: data[0].woeid,
});
},
(error) => {
dispatch({
type: ActionTypes.GET_CURRENT_LOCATION_COORDINATES_DENIED,
type: ActionTypes.GET_CURRENT_LOCATION_POSITION_DENIED,
payload: error.message,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/store/action-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export enum ActionTypes {
WEATHER_DEGREE_IS_FAHRENHEIT = "WEATHER_DEGREE_IS_FAHRENHEIT",
GET_LOCATION_FROM_MAP = "GET_LOCATION_FROM_MAP",
GET_LOCATION_COORDINATES = "GET_LOCATION_COORDINATES",
GET_CURRENT_LOCATION_COORDINATES = "GET_CURRENT_LOCATION_COORDINATES",
GET_CURRENT_LOCATION_COORDINATES_DENIED = "GET_CURRENT_LOCATION_COORDINATES_DENIED",
GET_CURRENT_LOCATION_POSITION = "GET_CURRENT_LOCATION_POSITION",
GET_CURRENT_LOCATION_POSITION_DENIED = "GET_CURRENT_LOCATION_POSITION_DENIED",
}
9 changes: 3 additions & 6 deletions src/store/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ interface getLocationCoordsAction {
}

interface getCurrentLocationAction {
type: ActionTypes.GET_CURRENT_LOCATION_COORDINATES;
payload: {
lat: string;
lon: string;
};
type: ActionTypes.GET_CURRENT_LOCATION_POSITION;
payload: number;
}

interface getCurrentLocationDeniedAction {
type: ActionTypes.GET_CURRENT_LOCATION_COORDINATES_DENIED;
type: ActionTypes.GET_CURRENT_LOCATION_POSITION_DENIED;
payload: string;
}

Expand Down
13 changes: 6 additions & 7 deletions src/store/reducers/weatherReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,17 @@ const weatherReducer = (
woeid: action.payload,
error: null,
};
case ActionTypes.GET_CURRENT_LOCATION_COORDINATES_DENIED:
case ActionTypes.GET_CURRENT_LOCATION_POSITION:
return {
...state,
loading: false,
error: action.payload,
coords: null,
woeid: action.payload,
error: null,
};
case ActionTypes.GET_CURRENT_LOCATION_COORDINATES:
case ActionTypes.GET_CURRENT_LOCATION_POSITION_DENIED:
return {
...state,
coords: action.payload,
error: null,
loading: false,
coords: null,
};
default:
return state;
Expand Down

0 comments on commit 7c30091

Please sign in to comment.