mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
first bits of redux
This commit is contained in:
parent
9c7f7fda73
commit
def2b0d2a3
13 changed files with 170 additions and 16 deletions
|
@ -4,8 +4,10 @@ import App, { Container } from 'next/app'
|
|||
import Head from 'next/head'
|
||||
import Layout from '../components/layout'
|
||||
import { withCookies } from '../config/rpc'
|
||||
import { Provider } from 'react-redux'
|
||||
import ErrorP, { Overlay } from './_error'
|
||||
import styled from 'styled-components'
|
||||
import { withRedux } from '../config/redux'
|
||||
|
||||
type NextPage = React.Component<any> & React.StatelessFunctionalComponent<any> & {
|
||||
getInitialProps: (ctx: any, ...args: any) => any
|
||||
|
@ -58,7 +60,7 @@ class RoleypolyApp extends App {
|
|||
}
|
||||
|
||||
render () {
|
||||
const { Component, pageProps, router, user, layout, robots } = this.props
|
||||
const { Component, pageProps, router, user, layout, robots, store } = this.props
|
||||
// Fix for next/error rendering instead of our error page.
|
||||
// Who knows why this would ever happen.
|
||||
const ErrorCaughtComponent = (Component.displayName === 'ErrorPage' || Component.constructor.name === 'ErrorPage') ? ErrorP : Component
|
||||
|
@ -84,11 +86,13 @@ class RoleypolyApp extends App {
|
|||
})(document);//
|
||||
` }} />
|
||||
</Head>
|
||||
<Layout user={user} {...layout}>
|
||||
<ErrorCaughtComponent {...pageProps} router={router} originalName={Component.displayName || Component.constructor.name} />
|
||||
</Layout>
|
||||
<Provider store={store}>
|
||||
<Layout user={user} {...layout}>
|
||||
<ErrorCaughtComponent {...pageProps} router={router} originalName={Component.displayName || Component.constructor.name} />
|
||||
</Layout>
|
||||
</Provider>
|
||||
</Container>
|
||||
}
|
||||
}
|
||||
|
||||
export default RoleypolyApp
|
||||
export default withRedux(RoleypolyApp)
|
||||
|
|
|
@ -4,25 +4,65 @@ import Head from 'next/head'
|
|||
import type { PageProps } from '../../types'
|
||||
import SocialCards from '../../components/social-cards'
|
||||
import redirect from '../../lib/redirect'
|
||||
import { connect } from 'react-redux'
|
||||
import { fetchServerIfNeed, getCurrentServerState, type ServerState } from '../../stores/currentServer'
|
||||
import { renderRoles, getCurrentRoles } from '../../stores/roles'
|
||||
|
||||
export default class Server extends React.Component<PageProps> {
|
||||
type ServerPageProps = PageProps & {
|
||||
currentServer: ServerState
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, { router: { query: { id } } }) => {
|
||||
return {
|
||||
currentServer: getCurrentServerState(state, id),
|
||||
roles: getCurrentRoles(state, id)
|
||||
}
|
||||
}
|
||||
|
||||
class Server extends React.Component<ServerPageProps> {
|
||||
static async getInitialProps (ctx: *, rpc: *, router: *) {
|
||||
if (ctx.user == null) {
|
||||
redirect(ctx, `/auth/login?r=${router.asPath}`)
|
||||
}
|
||||
|
||||
ctx.robots = 'NOINDEX, NOFOLLOW'
|
||||
try {
|
||||
if (router.query.id == null) {
|
||||
console.warn({ query: router.query })
|
||||
}
|
||||
ctx.store.dispatch(fetchServerIfNeed(router.query.id, rpc))
|
||||
ctx.store.dispatch(renderRoles(router.query.id))
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
const { currentServer, router: { query: { id } }, dispatch } = this.props
|
||||
if (currentServer == null) {
|
||||
this.props.router.push('/s/add')
|
||||
}
|
||||
|
||||
dispatch(fetchServerIfNeed(id))
|
||||
}
|
||||
|
||||
render () {
|
||||
const { currentServer } = this.props
|
||||
console.log({ currentServer })
|
||||
if (currentServer == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title key='title'>server name!</title>
|
||||
<title key='title'>{currentServer.server.name} - Roleypoly</title>
|
||||
</Head>
|
||||
<SocialCards title={'server test'} />
|
||||
hello {this.props.router.query.id}
|
||||
<SocialCards title={`${currentServer.server.name} on Roleypoly`} />
|
||||
hello <span style={{ color: currentServer.gm.color }}>{currentServer.gm.nickname}</span> on {currentServer.server.name}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(Server)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue