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 Link from 'next/link'
|
||||||
|
|
||||||
import tabs from '../data/tabs.json'
|
import tabs from '../data/tabs.json'
|
||||||
import constants from '../constants.json'
|
import constants from '../constants.json'
|
||||||
|
|
||||||
|
// FIXME: window resize event listener to show sidebar on resize
|
||||||
|
|
||||||
export default function Layout (props) {
|
export default function Layout (props) {
|
||||||
let href = props.route
|
let href = props.route
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(true)
|
const [sidebarOpen, setSidebarOpen] = useState(true)
|
||||||
|
@ -12,9 +14,18 @@ export default function Layout (props) {
|
||||||
href = 'index'
|
href = 'index'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const closeSideBar = () => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
console.log(window)
|
console.log('window.innerWidth', window.innerWidth)
|
||||||
|
if (window.innerWidth < constants.mobileWindowWidth) {
|
||||||
|
setSidebarOpen(false)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
closeSideBar()
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -36,6 +47,7 @@ export default function Layout (props) {
|
||||||
return (
|
return (
|
||||||
<Link href={item.href} key={key} >
|
<Link href={item.href} key={key} >
|
||||||
<a
|
<a
|
||||||
|
onClick={closeSideBar}
|
||||||
className={href.includes(key) ? 'active' : ''}
|
className={href.includes(key) ? 'active' : ''}
|
||||||
>{item.text}</a>
|
>{item.text}</a>
|
||||||
</Link>
|
</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