mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Hiding sidebar on click on mobile
This commit is contained in:
parent
6688a1417d
commit
98d2fb5e85
2 changed files with 15 additions and 35 deletions
|
@ -1,9 +1,11 @@
|
|||
import React, { useState } from 'react'
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import Link from 'next/link'
|
||||
|
||||
import tabs from '../data/tabs.json'
|
||||
import constants from '../constants.json'
|
||||
|
||||
// FIXME: window resize event listener to show sidebar on resize
|
||||
|
||||
export default function Layout (props) {
|
||||
let href = props.route
|
||||
const [sidebarOpen, setSidebarOpen] = useState(true)
|
||||
|
@ -12,10 +14,19 @@ export default function Layout (props) {
|
|||
href = 'index'
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
console.log(window)
|
||||
const closeSideBar = () => {
|
||||
if (typeof window !== 'undefined') {
|
||||
console.log('window.innerWidth', window.innerWidth)
|
||||
if (window.innerWidth < constants.mobileWindowWidth) {
|
||||
setSidebarOpen(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
closeSideBar()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className='sidebar'>
|
||||
|
@ -36,6 +47,7 @@ export default function Layout (props) {
|
|||
return (
|
||||
<Link href={item.href} key={key} >
|
||||
<a
|
||||
onClick={closeSideBar}
|
||||
className={href.includes(key) ? 'active' : ''}
|
||||
>{item.text}</a>
|
||||
</Link>
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
import React, { PureComponent } from 'react'
|
||||
|
||||
import links from './links.json'
|
||||
import constants from '../constants.json'
|
||||
|
||||
// TODO: aludni
|
||||
class HomeTab extends PureComponent {
|
||||
render () {
|
||||
return (<div>HAAAAAAAAAA</div>)
|
||||
// return (
|
||||
// <div>
|
||||
// {Object.keys(links).map((key) => {
|
||||
// const link = links[key]
|
||||
// return (
|
||||
// <div
|
||||
// className='link'
|
||||
// key={key}
|
||||
// >
|
||||
// <a
|
||||
// href={constants.serverUrl + link.href}
|
||||
// >
|
||||
// {link.text}
|
||||
// </a>
|
||||
// </div>
|
||||
// )
|
||||
// })}
|
||||
// </div>
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
export default HomeTab
|
Loading…
Add table
Add a link
Reference in a new issue