Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Remove the isMobile (major)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Cuadra committed Sep 21, 2018
1 parent 11a7f4b commit 6b6ded0
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions src/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function shouldWorkout({
workoutOnWednesday,
workoutOnThursday,
workoutOnFriday,
workoutOnSaturday,
}) {
const weekdays = [
workoutOnSunday,
Expand All @@ -73,6 +74,7 @@ function shouldWorkout({
workoutOnWednesday,
workoutOnThursday,
workoutOnFriday,
workoutOnSaturday,
];
return weekdays[moment().day()];
}
Expand All @@ -92,7 +94,6 @@ class Layout extends Component {

this.state = {
drawerIsOpen: false,
isMobile: true,
isWorkoutDay: shouldWorkout(settings),
macrosRest,
macrosWorkout,
Expand All @@ -112,38 +113,6 @@ class Layout extends Component {
};
}

componentDidMount() {
window.addEventListener('resize', this.doSizeCheck);
this.doSizeCheck(true);
}

componentDidUpdate(prevProps, prevState) {
// a hack to help components layout that depend on window events
// The size of the content changes on drawer open and close
if (prevState.menuIsOpen !== this.state.menuIsOpen) {
setTimeout(() => {
window.dispatchEvent(new Event('resize'));
}, 300);
}
}

componentWillUnMount() {
window.removeEventListener('resize', this.doSizeCheck);
}

doSizeCheck = initial => {
const isMobile = window.innerWidth < 640;
const drawerIsOpen =
initial && window.innerWidth > 640 ? true : this.state.drawerIsOpen;

if (
this.state.isMobile !== isMobile ||
this.state.drawerIsOpen !== drawerIsOpen
) {
this.setState({ isMobile, drawerIsOpen });
}
};

handleTracker({ action, macro, value }) {
const macroCalories = convertMacroGramToCalories({ macro, value });

Expand Down Expand Up @@ -318,11 +287,9 @@ class Layout extends Component {
>
<TopAppBarRow>
<TopAppBarSection>
{state.isMobile && (
<TopAppBarActionItem alt="Menu" onClick={this.toggleDrawer}>
menu
</TopAppBarActionItem>
)}
<TopAppBarActionItem alt="Menu" onClick={this.toggleDrawer}>
menu
</TopAppBarActionItem>
<TopAppBarTitle>{props.pageTitle}</TopAppBarTitle>
</TopAppBarSection>
<TopAppBarSection alignEnd>
Expand All @@ -335,7 +302,7 @@ class Layout extends Component {
</TopAppBarRow>
</TopAppBar>

<div className="mdc-top-app-bar--dense-fixed-adjust appContent">
<div className="mdc-top-app-bar--dense-fixed-adjust">
<MenuDrawer
onClose={() => this.setState({ drawerIsOpen: false })}
open={state.drawerIsOpen}
Expand All @@ -344,12 +311,6 @@ class Layout extends Component {
{props.children}
</CoreContext.Provider>
</div>
<style jsx>{`
.appContent {
display: grid;
grid-template-columns: ${state.isMobile ? '' : 'auto '} 1fr;
}
`}</style>
</main>
);
}
Expand Down

0 comments on commit 6b6ded0

Please sign in to comment.