1
0
Fork 0
freesewing/packages/freesewing.shared/components/wrappers/page.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

import React, { useState, useEffect } from 'react'
2021-12-11 14:04:05 +01:00
import { useSwipeable } from 'react-swipeable'
2021-12-24 18:17:02 +01:00
import { useRouter } from 'next/router'
import { useHotkeys } from 'react-hotkeys-hook'
2021-12-11 14:04:05 +01:00
// Shared components
import Layout from 'shared/components/layouts/default'
/* This component should wrap all page content */
const PageWrapper= props => {
2021-12-11 14:04:05 +01:00
const swipeHandlers = useSwipeable({
onSwipedLeft: evt => (props.app.primaryMenu) ? props.app.setPrimaryMenu(false) : null,
onSwipedRight: evt => (props.app.primaryMenu) ? null : props.app.setPrimaryMenu(true),
trackMouse: true
})
2021-12-24 18:17:02 +01:00
const router = useRouter()
const slug = router.asPath.slice(1)
useEffect(() => props.app.setSlug(slug), [slug])
2021-12-11 14:04:05 +01:00
// Trigger search with Ctrl+k
useHotkeys('ctrl+k', (evt) => {
evt.preventDefault()
setSearch(true)
})
2021-12-11 14:04:05 +01:00
const [search, setSearch] = useState(false)
2021-12-11 14:04:05 +01:00
const childProps = {
app: props.app,
title: props.title,
search, setSearch, toggleSearch: () => setSearch(!search),
noSearch: props.noSearch,
workbench: props.workbench,
AltMenu: props.AltMenu || null
2021-12-11 14:04:05 +01:00
}
2021-12-11 14:04:05 +01:00
return (
<div
ref={swipeHandlers.ref}
onMouseDown={swipeHandlers.onMouseDown}
data-theme={props.app.theme}
key={props.app.theme} // Thiis forces the data-theme update
>
2021-12-11 14:04:05 +01:00
{props.noLayout
? props.children
2021-12-30 18:54:42 +01:00
: <Layout {...childProps}>{props.children}</Layout>
2021-12-11 14:04:05 +01:00
}
</div>
2021-12-11 14:04:05 +01:00
)
}
export default PageWrapper
2021-12-11 14:04:05 +01:00