Skip to content

Commit

Permalink
🐛 fix bug: window is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed Jul 6, 2018
1 parent 12c52f5 commit b73d886
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
38 changes: 25 additions & 13 deletions src/templates/post.jsx
Expand Up @@ -14,6 +14,12 @@ import { slide as Menu } from 'react-burger-menu'


export default class PostTemplate extends React.Component {

constructor(props) {
super(props);
this.state = {isOpen: true, updateDimensions:null};
}

componentDidMount() {
tocbot.init({
// Where to render the table of contents.
Expand All @@ -23,24 +29,30 @@ export default class PostTemplate extends React.Component {
// Which headings to grab inside of the contentSelector element.
headingSelector: 'h1, h2, h3',
});
window.addEventListener("resize", this.updateDimensions.bind(this));
}
constructor(props) {
super(props);
this.state = {isOpen: true};

let updateDimensions = function(){
if(typeof window !== 'undefined')
if(window.innerWidth < 900)
this.setState({isOpen:false, updateDimensions:updateDimensions});
else
this.setState({isOpen:true, updateDimensions:updateDimensions});
else
this.setState({isOpen:false, updateDimensions:updateDimensions});
};
window.addEventListener("resize", updateDimensions.bind(this));
}

updateDimensions() {
if(window.innerWidth < 900){
this.setState({isOpen:false});
}else
this.setState({isOpen:true});
}
componentWillMount() {
this.updateDimensions();
// const windowGlobal = typeof window !== 'undefined' && window;
// console.log(this.state.windowGlobal.innerWidth);
// if(this.state.window.innerWidth < 900){
// this.setState({isOpen:false});
// }else
// this.setState({isOpen:true});
}

componentWillUnmount() {
window.removeEventListener("resize", this.updateDimensions);
window.removeEventListener("resize", this.state.updateDimensions);
}

render() {
Expand Down
14 changes: 7 additions & 7 deletions src/templates/styles.scss
Expand Up @@ -7,13 +7,13 @@
@import url("tocbot.css");
// @import url("fonts/supermarket.css");

@font-face {
font-family: 'supermarket';
src: url('/assets/fonts/supermarket.woff2') format('woff2'),
url('/assets/fonts/supermarket.woff') format('woff');
font-weight: normal;
font-style: normal;
}
// @font-face {
// font-family: 'supermarket';
// src: url('/assets/fonts/supermarket.woff2') format('woff2'),
// url('/assets/fonts/supermarket.woff') format('woff');
// font-weight: normal;
// font-style: normal;
// }

.tag-label {
margin: 0 0.1em;
Expand Down

0 comments on commit b73d886

Please sign in to comment.