mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 12:19:10 +00:00
sync
This commit is contained in:
parent
86a222fb98
commit
032831aff1
5 changed files with 138 additions and 17 deletions
|
@ -3,31 +3,66 @@ import { Redirect } from 'react-router-dom'
|
||||||
import superagent from 'superagent'
|
import superagent from 'superagent'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { fetchServers } from '../../actions'
|
import { fetchServers } from '../../actions'
|
||||||
|
import { URL } from 'url';
|
||||||
|
|
||||||
@connect()
|
@connect()
|
||||||
class OauthCallback extends Component {
|
class OauthCallback extends Component {
|
||||||
state = {
|
state = {
|
||||||
notReady: true,
|
notReady: true,
|
||||||
message: 'chotto matte kudasai...'
|
message: 'chotto matte kudasai...',
|
||||||
|
redirect: '/s'
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchUser () {
|
||||||
|
const rsp = await superagent.get('/api/auth/user')
|
||||||
|
sessionStorage.setItem('user', JSON.stringify(rsp.body))
|
||||||
|
sessionStorage.setItem('user.update', JSON.stringify(Date.now()))
|
||||||
|
this.props.dispatch({
|
||||||
|
type: Symbol.for('set user'),
|
||||||
|
data: rsp.body
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setupUser () {
|
||||||
|
const userUpdateTime = sessionStorage.getItem('user.update') || 0
|
||||||
|
if (+userUpdateTime + (1000 * 60 * 10) > Date.now()) {
|
||||||
|
const user = sessionStorage.getItem('user')
|
||||||
|
if (user != null && user !== '') {
|
||||||
|
this.props.dispatch({
|
||||||
|
type: Symbol.for('set user'),
|
||||||
|
data: JSON.parse(user)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.fetchUser()
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount () {
|
async componentDidMount () {
|
||||||
const { body: { url } } = await superagent.get('/api/auth/redirect?url=✔️')
|
const oUrl = new URL(window.location.href)
|
||||||
|
if (oUrl.searchParams.has('r')) {
|
||||||
|
this.setState({ redirect: oUrl.searchParams.get('r') })
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const rsp = await superagent.get('/api/auth/user')
|
await this.setupUser()
|
||||||
this.props.dispatch({
|
|
||||||
type: Symbol.for('set user'),
|
|
||||||
data: rsp.body
|
|
||||||
})
|
|
||||||
this.props.dispatch(fetchServers)
|
this.props.dispatch(fetchServers)
|
||||||
this.setState({ notReady: false })
|
this.setState({ notReady: false })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.location.href = url
|
const { body: { url } } = await superagent.get('/api/auth/redirect?url=✔️')
|
||||||
|
const nUrl = new URL(url)
|
||||||
|
|
||||||
|
if (oUrl.searchParams.has('r')) {
|
||||||
|
nUrl.searchParams.set('r', oUrl.searchParams.get('r'))
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.href = nUrl.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (this.state.notReady) ? this.state.message : <Redirect to='/s' />
|
return (this.state.notReady) ? this.state.message : <Redirect to={this.state.redirect} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
UI/src/pages/Error404.js
Normal file
35
UI/src/pages/Error404.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import React, { Component, Fragment } from 'react'
|
||||||
|
import { Link } from 'react-router-dom'
|
||||||
|
import Scrollbars from 'react-custom-scrollbars'
|
||||||
|
import Typist from 'react-typist'
|
||||||
|
import moment from 'moment'
|
||||||
|
import './landing.sass'
|
||||||
|
import discordLogo from './images/discord-logo.svg'
|
||||||
|
import RoleypolyDemo from '../components/demos/roleypoly'
|
||||||
|
import TypingDemo from '../components/demos/typing'
|
||||||
|
|
||||||
|
const Landing = ({ root = false }) =>
|
||||||
|
<div className="landing uk-width-1-1 uk-text-center">
|
||||||
|
<div className="uk-container">
|
||||||
|
<section>
|
||||||
|
<h1>Self-assignable Discord roles for humans.</h1>
|
||||||
|
<h4>Ditch bot commands once and for all.</h4>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<Link to="/oauth/flow" className="uk-button rp-button discord"><img src={discordLogo} className="rp-button-logo"/> Sign in with Discord</Link>
|
||||||
|
</section>
|
||||||
|
<section uk-grid="">
|
||||||
|
{/* Typist */}
|
||||||
|
<div className="uk-width-1-2">
|
||||||
|
<TypingDemo />
|
||||||
|
<p className="subtext">Why are we stuck in the stupid ages?</p>
|
||||||
|
</div>
|
||||||
|
{/* role side */}
|
||||||
|
<div className="uk-width-1-2">
|
||||||
|
<RoleypolyDemo />
|
||||||
|
<p className="subtext">It's 2018. We can do better.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
export default Landing
|
35
UI/src/pages/ServerLanding.js
Normal file
35
UI/src/pages/ServerLanding.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import React, { Component, Fragment } from 'react'
|
||||||
|
import { Link } from 'react-router-dom'
|
||||||
|
import Scrollbars from 'react-custom-scrollbars'
|
||||||
|
import Typist from 'react-typist'
|
||||||
|
import moment from 'moment'
|
||||||
|
import './landing.sass'
|
||||||
|
import discordLogo from './images/discord-logo.svg'
|
||||||
|
import RoleypolyDemo from '../components/demos/roleypoly'
|
||||||
|
import TypingDemo from '../components/demos/typing'
|
||||||
|
|
||||||
|
const Landing = ({ root = false }) =>
|
||||||
|
<div className="landing uk-width-1-1 uk-text-center">
|
||||||
|
<div className="uk-container">
|
||||||
|
<section>
|
||||||
|
<h1>Self-assignable Discord roles for humans.</h1>
|
||||||
|
<h4>Ditch bot commands once and for all.</h4>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<Link to="/oauth/flow" className="uk-button rp-button discord"><img src={discordLogo} className="rp-button-logo"/> Sign in with Discord</Link>
|
||||||
|
</section>
|
||||||
|
<section uk-grid="">
|
||||||
|
{/* Typist */}
|
||||||
|
<div className="uk-width-1-2">
|
||||||
|
<TypingDemo />
|
||||||
|
<p className="subtext">Why are we stuck in the stupid ages?</p>
|
||||||
|
</div>
|
||||||
|
{/* role side */}
|
||||||
|
<div className="uk-width-1-2">
|
||||||
|
<RoleypolyDemo />
|
||||||
|
<p className="subtext">It's 2018. We can do better.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
export default Landing
|
|
@ -4,10 +4,10 @@ import Scrollbars from 'react-custom-scrollbars'
|
||||||
import './pages.sass'
|
import './pages.sass'
|
||||||
|
|
||||||
import WhyNoRoles from './WhyNoRoles'
|
import WhyNoRoles from './WhyNoRoles'
|
||||||
import LandingPage from './Landing'
|
import Error404 from './Error404'
|
||||||
export const Landing = LandingPage // re-export
|
export { default as Landing } from './Landing'
|
||||||
|
export { default as ServerLanding } from './ServerLanding'
|
||||||
const isDev = process.env.NODE_ENV === 'development'
|
export { default as Error404 } from './Error404'
|
||||||
|
|
||||||
const Pages = (props) => {
|
const Pages = (props) => {
|
||||||
return <div className="pages">
|
return <div className="pages">
|
||||||
|
@ -16,6 +16,7 @@ const Pages = (props) => {
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/help/why-no-roles" component={WhyNoRoles} />
|
<Route path="/help/why-no-roles" component={WhyNoRoles} />
|
||||||
{/* { isDev ? <Route path="/p/landing" component={Landing} /> : null } */}
|
{/* { isDev ? <Route path="/p/landing" component={Landing} /> : null } */}
|
||||||
|
<Route component={Error404} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
</Scrollbars>
|
</Scrollbars>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import Servers from '../components/servers'
|
||||||
import OauthCallback from '../components/oauth-callback'
|
import OauthCallback from '../components/oauth-callback'
|
||||||
import OauthFlow from '../components/oauth-flow'
|
import OauthFlow from '../components/oauth-flow'
|
||||||
import OauthBotFlow from '../components/oauth-bot-flow'
|
import OauthBotFlow from '../components/oauth-bot-flow'
|
||||||
import Pages, { Landing } from '../pages'
|
import Pages, { Landing, Error404, ServerLanding } from '../pages'
|
||||||
|
|
||||||
const aaa = (props) => (<div>{ JSON.stringify(props) }</div>)
|
const aaa = (props) => (<div>{ JSON.stringify(props) }</div>)
|
||||||
|
|
||||||
|
@ -15,15 +15,28 @@ const aaa = (props) => (<div>{ JSON.stringify(props) }</div>)
|
||||||
@connect(({ appState, user }) => ({ ready: appState.ready, user }))
|
@connect(({ appState, user }) => ({ ready: appState.ready, user }))
|
||||||
export default class AppRouter extends Component {
|
export default class AppRouter extends Component {
|
||||||
render () {
|
render () {
|
||||||
|
const isLoggedIn = this.props.user.get('isLoggedIn')
|
||||||
|
|
||||||
if (!this.props.ready) {
|
if (!this.props.ready) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Switch>
|
return <Switch>
|
||||||
<Route path='/s' component={Servers} />
|
{ (isLoggedIn)
|
||||||
|
|
||||||
<Route path='/root' component={aaa} />
|
// YES LOGGED IN
|
||||||
|
? <Fragment>
|
||||||
|
<Route path='/s' component={Servers} />
|
||||||
|
<Route path='/root' component={aaa} />
|
||||||
|
</Fragment>
|
||||||
|
|
||||||
|
// NOT LOGGED IN
|
||||||
|
: <Fragment>
|
||||||
|
<Route path='/s' component={ServerLanding} />
|
||||||
|
</Fragment>
|
||||||
|
}
|
||||||
|
|
||||||
|
{/* GENERAL ROUTES */}
|
||||||
<Route path='/oauth/callback' component={OauthCallback} />
|
<Route path='/oauth/callback' component={OauthCallback} />
|
||||||
<Route path='/oauth/flow' component={OauthFlow} />
|
<Route path='/oauth/flow' component={OauthFlow} />
|
||||||
<Route path='/oauth/bot/flow' component={OauthBotFlow} />
|
<Route path='/oauth/bot/flow' component={OauthBotFlow} />
|
||||||
|
@ -32,10 +45,12 @@ export default class AppRouter extends Component {
|
||||||
<Route path='/help' component={Pages} />
|
<Route path='/help' component={Pages} />
|
||||||
|
|
||||||
<Route exact path='/' render={() =>
|
<Route exact path='/' render={() =>
|
||||||
this.props.user.get('isLoggedIn')
|
isLoggedIn
|
||||||
? <Redirect to="/s" />
|
? <Redirect to="/s" />
|
||||||
: <Landing root={true} />
|
: <Landing root={true} />
|
||||||
} />
|
} />
|
||||||
|
|
||||||
|
<Route component={Error404} />
|
||||||
</Switch>
|
</Switch>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue