diff --git a/UI/src/components/oauth-flow/index.js b/UI/src/components/oauth-flow/index.js
index 8214dab..200e853 100644
--- a/UI/src/components/oauth-flow/index.js
+++ b/UI/src/components/oauth-flow/index.js
@@ -3,31 +3,66 @@ import { Redirect } from 'react-router-dom'
import superagent from 'superagent'
import { connect } from 'react-redux'
import { fetchServers } from '../../actions'
+import { URL } from 'url';
@connect()
class OauthCallback extends Component {
state = {
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 () {
- 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 {
- const rsp = await superagent.get('/api/auth/user')
- this.props.dispatch({
- type: Symbol.for('set user'),
- data: rsp.body
- })
+ await this.setupUser()
+
this.props.dispatch(fetchServers)
this.setState({ notReady: false })
} 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 () {
- return (this.state.notReady) ? this.state.message :
+ return (this.state.notReady) ? this.state.message :
}
}
diff --git a/UI/src/pages/Error404.js b/UI/src/pages/Error404.js
new file mode 100644
index 0000000..2c2706b
--- /dev/null
+++ b/UI/src/pages/Error404.js
@@ -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 }) =>
+
+
+
+ Self-assignable Discord roles for humans.
+ Ditch bot commands once and for all.
+
+
+
Sign in with Discord
+
+
+ {/* Typist */}
+
+
+
Why are we stuck in the stupid ages?
+
+ {/* role side */}
+
+
+
It's 2018. We can do better.
+
+
+
+
+export default Landing
diff --git a/UI/src/pages/ServerLanding.js b/UI/src/pages/ServerLanding.js
new file mode 100644
index 0000000..2c2706b
--- /dev/null
+++ b/UI/src/pages/ServerLanding.js
@@ -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 }) =>
+
+
+
+ Self-assignable Discord roles for humans.
+ Ditch bot commands once and for all.
+
+
+
Sign in with Discord
+
+
+ {/* Typist */}
+
+
+
Why are we stuck in the stupid ages?
+
+ {/* role side */}
+
+
+
It's 2018. We can do better.
+
+
+
+
+export default Landing
diff --git a/UI/src/pages/index.js b/UI/src/pages/index.js
index f346fae..81d4591 100644
--- a/UI/src/pages/index.js
+++ b/UI/src/pages/index.js
@@ -4,10 +4,10 @@ import Scrollbars from 'react-custom-scrollbars'
import './pages.sass'
import WhyNoRoles from './WhyNoRoles'
-import LandingPage from './Landing'
-export const Landing = LandingPage // re-export
-
-const isDev = process.env.NODE_ENV === 'development'
+import Error404 from './Error404'
+export { default as Landing } from './Landing'
+export { default as ServerLanding } from './ServerLanding'
+export { default as Error404 } from './Error404'
const Pages = (props) => {
return
@@ -16,6 +16,7 @@ const Pages = (props) => {
{/* { isDev ? : null } */}
+
diff --git a/UI/src/router/index.js b/UI/src/router/index.js
index f155134..0ec1bae 100644
--- a/UI/src/router/index.js
+++ b/UI/src/router/index.js
@@ -7,7 +7,7 @@ import Servers from '../components/servers'
import OauthCallback from '../components/oauth-callback'
import OauthFlow from '../components/oauth-flow'
import OauthBotFlow from '../components/oauth-bot-flow'
-import Pages, { Landing } from '../pages'
+import Pages, { Landing, Error404, ServerLanding } from '../pages'
const aaa = (props) => ({ JSON.stringify(props) }
)
@@ -15,15 +15,28 @@ const aaa = (props) => ({ JSON.stringify(props) }
)
@connect(({ appState, user }) => ({ ready: appState.ready, user }))
export default class AppRouter extends Component {
render () {
+ const isLoggedIn = this.props.user.get('isLoggedIn')
+
if (!this.props.ready) {
return null
}
return
-
+ { (isLoggedIn)
-
+ // YES LOGGED IN
+ ?
+
+
+
+
+ // NOT LOGGED IN
+ :
+
+
+ }
+ {/* GENERAL ROUTES */}
@@ -32,10 +45,12 @@ export default class AppRouter extends Component {
- this.props.user.get('isLoggedIn')
+ isLoggedIn
?
:
} />
+
+
}
}