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

Commit

Permalink
Fix SSR load. (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Cuadra committed Sep 22, 2018
1 parent f171aed commit 71160a3
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { calculateDayMenu, calculateSettings, prioritizeAndSort } from './util';
import { convertMacroGramToCalories } from './calculator/utils';
import demoRecipes from '../data/recipes';

function loadLocalValues() {
if (typeof window === 'undefined') {
function loadLocalValues(isSSR) {
if (isSSR) {
return {
isWorkoutDay: false,
macrosRest: {},
Expand Down Expand Up @@ -90,7 +90,7 @@ class Layout extends Component {
recipesFavoriteKeys,
settings,
tracker,
} = loadLocalValues();
} = loadLocalValues(true);

this.state = {
drawerIsOpen: false,
Expand All @@ -113,6 +113,29 @@ class Layout extends Component {
};
}

componentDidMount() {
const {
macrosRest,
macrosWorkout,
menu,
recipes,
recipesFavoriteKeys,
settings,
tracker,
} = loadLocalValues();

this.setState({
isWorkoutDay: shouldWorkout(settings),
macrosRest,
macrosWorkout,
menu,
recipes,
recipesFavoriteKeys,
settings,
tracker,
});
}

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

Expand Down

0 comments on commit 71160a3

Please sign in to comment.