absolutely massive typescript porting time

This commit is contained in:
41666 2019-06-02 18:58:15 -05:00
parent 01f238f515
commit 30d08a630f
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
159 changed files with 2563 additions and 3861 deletions

View file

@ -6,8 +6,8 @@ import DiscordButton from '../../components/discord-button'
import RPC from '../../config/rpc'
import redirect from '../../util/redirect'
import dynamic from 'next/dynamic'
import type { PageProps } from '../../types'
import type { ServerSlug } from '@roleypoly/types'
import { PageProps } from '../../types'
import { ServerSlug } from '@roleypoly/types'
import getConfig from 'next/config'
const { publicRuntimeConfig: { BOT_HANDLE } } = getConfig()
@ -17,8 +17,8 @@ type AuthLoginState = {
}
type AuthLoginProps = PageProps & {
redirect: ?string,
redirectSlug: ?ServerSlug
redirect?: string,
redirectSlug?: ServerSlug
}
const Wrapper = styled.div`
@ -124,8 +124,8 @@ export default class AuthLogin extends React.Component<AuthLoginProps, AuthLogin
waiting: false
}
static async getInitialProps (ctx: *, rpc: typeof RPC, router: *) {
let { r } = (router.query: { r: string })
static async getInitialProps (ctx: any, rpc: typeof RPC, router: any) {
let { r } = (router.query as { r?: string })
if (ctx.user != null) {
redirect(ctx, r || '/')
@ -133,17 +133,19 @@ export default class AuthLogin extends React.Component<AuthLoginProps, AuthLogin
ctx.robots = 'NOINDEX, NOFOLLOW'
if (r != null) {
let redirectSlug = null
if (r !== undefined) {
let redirectSlug: ServerSlug | null = null
if (r.startsWith('/s/') && r !== '/s/add') {
redirectSlug = await rpc.getServerSlug(r.replace('/s/', ''))
}
return { redirect: r, redirectSlug }
}
return {}
}
componentDidMount () {
if (this.props.redirect != null) {
if (this.props.redirect !== undefined) {
this.props.router.replace(this.props.router.pathname)
}
}
@ -176,7 +178,7 @@ export default class AuthLogin extends React.Component<AuthLoginProps, AuthLogin
render () {
return <Wrapper>
<div>
{(this.props.redirectSlug != null) ? <Slug {...this.props.redirectSlug} /> : null}
{(this.props.redirectSlug !== undefined) ? <Slug {...this.props.redirectSlug} /> : null}
<DiscordButton href={`/api/auth/redirect?r=${this.props.redirect || '/'}`}>Sign in with Discord</DiscordButton>
<Line />
<div>