mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 20:19:12 +00:00
add router data to header
This commit is contained in:
parent
456da9cd0c
commit
73f60cbd3d
4 changed files with 23 additions and 13 deletions
|
@ -7,6 +7,7 @@ import styled from 'styled-components'
|
||||||
import { Hide } from '../../kit/media'
|
import { Hide } from '../../kit/media'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
|
import { getCurrentServerState } from '../../stores/currentServer'
|
||||||
|
|
||||||
const temporaryServer = {
|
const temporaryServer = {
|
||||||
id: '423497622876061707',
|
id: '423497622876061707',
|
||||||
|
@ -47,10 +48,10 @@ const StyledAvatar = styled.img`
|
||||||
|
|
||||||
const ServerSelector = (props) => <div {...props}>
|
const ServerSelector = (props) => <div {...props}>
|
||||||
<div>
|
<div>
|
||||||
<StyledServerPic {...temporaryServer} />
|
<StyledServerPic {...props} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{ temporaryServer.name }
|
{ props.name }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -73,22 +74,27 @@ const StyledUserSection = styled(UserSection)`
|
||||||
text-align: right;
|
text-align: right;
|
||||||
`
|
`
|
||||||
|
|
||||||
const HeaderBarAuth: React.StatelessFunctionalComponent<{ user: User }> = ({ user }) => (
|
const Spacer = styled.div`
|
||||||
|
flex: 1;
|
||||||
|
`
|
||||||
|
|
||||||
|
const HeaderBarAuth: React.StatelessFunctionalComponent<{ user: User, isOnServer: boolean, currentServer: * }> = ({ user, isOnServer, currentServer = temporaryServer }) => (
|
||||||
<HeaderBarCommon noBackground={false}>
|
<HeaderBarCommon noBackground={false}>
|
||||||
<>
|
<>
|
||||||
<Link href='/s/add' prefetch>
|
<Link href='/'>
|
||||||
<LogoBox>
|
<LogoBox>
|
||||||
<Logomark />
|
<Logomark />
|
||||||
</LogoBox>
|
</LogoBox>
|
||||||
</Link>
|
</Link>
|
||||||
<StyledServerSelector />
|
{ isOnServer ? <StyledServerSelector name={currentServer.name} id={currentServer.id} icon={currentServer.icon} /> : <Spacer /> }
|
||||||
<StyledUserSection user={user} />
|
<StyledUserSection user={user} />
|
||||||
</>
|
</>
|
||||||
</HeaderBarCommon>
|
</HeaderBarCommon>
|
||||||
)
|
)
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = (state, { router }) => ({
|
||||||
|
isOnServer: router.pathname === '/_internal/_server',
|
||||||
}
|
currentServer: router.pathname === '/_internal/_server' ? getCurrentServerState(state, router.query.id).server : {}
|
||||||
|
})
|
||||||
|
|
||||||
export default connect(mapStateToProps)(HeaderBarAuth)
|
export default connect(mapStateToProps)(HeaderBarAuth)
|
||||||
|
|
|
@ -17,7 +17,7 @@ const Header = styled.div`
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
z-index: 100;
|
z-index: 5;
|
||||||
`
|
`
|
||||||
|
|
||||||
const HeaderInner = styled.div`
|
const HeaderInner = styled.div`
|
||||||
|
|
|
@ -23,11 +23,11 @@ const ContentBox = styled.div`
|
||||||
/* max-height: calc(100vh - 50px); */
|
/* max-height: calc(100vh - 50px); */
|
||||||
`
|
`
|
||||||
|
|
||||||
const Layout = ({ children, user, noBackground }: {children: React.Element<any>, user: User, noBackground: boolean }) => <>
|
const Layout = ({ children, user, noBackground, router }: {children: React.Element<any>, user: User, noBackground: boolean, router: * }) => <>
|
||||||
<GlobalColors />
|
<GlobalColors />
|
||||||
<SocialCards />
|
<SocialCards />
|
||||||
<LayoutWrapper>
|
<LayoutWrapper>
|
||||||
<HeaderBar user={user} noBackground={noBackground} />
|
<HeaderBar user={user} noBackground={noBackground} router={router} />
|
||||||
<ContentBox>
|
<ContentBox>
|
||||||
{children}
|
{children}
|
||||||
</ContentBox>
|
</ContentBox>
|
||||||
|
|
|
@ -56,7 +56,11 @@ class RoleypolyApp extends App {
|
||||||
catchFOUC () {
|
catchFOUC () {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (document.documentElement) document.documentElement.className += ' force-active'
|
if (document.documentElement) document.documentElement.className += ' force-active'
|
||||||
}, 1500)
|
}, 700)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
this.catchFOUC()
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
@ -87,7 +91,7 @@ class RoleypolyApp extends App {
|
||||||
` }} />
|
` }} />
|
||||||
</Head>
|
</Head>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<Layout user={user} {...layout}>
|
<Layout user={user} {...layout} router={router}>
|
||||||
<ErrorCaughtComponent {...pageProps} router={router} originalName={Component.displayName || Component.constructor.name} />
|
<ErrorCaughtComponent {...pageProps} router={router} originalName={Component.displayName || Component.constructor.name} />
|
||||||
</Layout>
|
</Layout>
|
||||||
</Provider>
|
</Provider>
|
||||||
|
|
Loading…
Add table
Reference in a new issue