2024-02-23 15:32:20 +00:00
|
|
|
import { Nav, Navbar } from 'react-bootstrap'
|
|
|
|
import { Brand, NavNotifications, PostItem, SearchItem } from '../common'
|
|
|
|
import { useMe } from '../../me'
|
|
|
|
import styles from './footer.module.css'
|
|
|
|
import classNames from 'classnames'
|
|
|
|
import Offcanvas from './offcanvas'
|
|
|
|
import { useRouter } from 'next/router'
|
2024-03-28 21:03:45 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
|
|
|
function useDetectKeyboardOpen (minKeyboardHeight = 300, defaultValue) {
|
|
|
|
const [isKeyboardOpen, setIsKeyboardOpen] = useState(defaultValue)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const listener = () => {
|
2024-03-28 23:18:44 +00:00
|
|
|
const newState = window.innerHeight - minKeyboardHeight > window.visualViewport.height
|
2024-03-28 21:03:45 +00:00
|
|
|
setIsKeyboardOpen(newState)
|
|
|
|
}
|
|
|
|
if (typeof visualViewport !== 'undefined') {
|
|
|
|
window.visualViewport.addEventListener('resize', listener)
|
|
|
|
}
|
|
|
|
return () => {
|
|
|
|
if (typeof visualViewport !== 'undefined') {
|
|
|
|
window.visualViewport.removeEventListener('resize', listener)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [setIsKeyboardOpen, minKeyboardHeight])
|
|
|
|
|
|
|
|
return isKeyboardOpen
|
|
|
|
}
|
2024-02-23 15:32:20 +00:00
|
|
|
|
|
|
|
export default function BottomBar ({ sub }) {
|
|
|
|
const router = useRouter()
|
2024-03-28 21:03:45 +00:00
|
|
|
const me = useMe()
|
2024-03-28 23:18:44 +00:00
|
|
|
const isKeyboardOpen = useDetectKeyboardOpen(200, false)
|
2024-02-23 15:32:20 +00:00
|
|
|
|
2024-03-28 21:03:45 +00:00
|
|
|
if (isKeyboardOpen) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = router.asPath.split('?')[0]
|
2024-02-23 15:32:20 +00:00
|
|
|
const props = {
|
|
|
|
prefix: sub ? `/~${sub}` : '',
|
|
|
|
path,
|
|
|
|
topNavKey: path.split('/')[sub ? 2 : 1] ?? '',
|
|
|
|
dropNavKey: path.split('/').slice(sub ? 2 : 1).join('/'),
|
|
|
|
sub
|
|
|
|
}
|
2024-03-28 21:03:45 +00:00
|
|
|
|
2024-02-23 15:32:20 +00:00
|
|
|
return (
|
2024-04-04 23:50:52 +00:00
|
|
|
<nav className='d-block d-md-none'>
|
|
|
|
<div style={{ marginBottom: '53px' }} className={styles.footerPadding} />
|
|
|
|
<div className={classNames(styles.footer, styles.footerPadding)}>
|
|
|
|
<Navbar className='container px-0'>
|
|
|
|
<Nav className={styles.footerNav}>
|
|
|
|
<Brand />
|
2024-05-04 23:07:09 +00:00
|
|
|
<SearchItem {...props} />
|
2024-04-04 23:50:52 +00:00
|
|
|
<PostItem {...props} className='btn-sm' />
|
2024-05-04 23:07:09 +00:00
|
|
|
<NavNotifications />
|
|
|
|
<Offcanvas me={me} {...props} />
|
2024-04-04 23:50:52 +00:00
|
|
|
</Nav>
|
|
|
|
</Navbar>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2024-02-23 15:32:20 +00:00
|
|
|
)
|
|
|
|
}
|