mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
improve social modes for discordbot crawler.
This commit is contained in:
parent
cd70c58cc9
commit
8dd759d78c
5 changed files with 44 additions and 5 deletions
6
ui/pages/_internal/_discordbot/_auth.js
Normal file
6
ui/pages/_internal/_discordbot/_auth.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import * as React from 'react'
|
||||
import SocialCards from '../../../components/social-cards'
|
||||
|
||||
export default () => <>
|
||||
<SocialCards title='Sign in on Roleypoly' />
|
||||
</>
|
6
ui/pages/_internal/_discordbot/_magic.js
Normal file
6
ui/pages/_internal/_discordbot/_magic.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import * as React from 'react'
|
||||
import SocialCards from '../../../components/social-cards'
|
||||
|
||||
export default () => <>
|
||||
<SocialCards title='Sign in on Roleypoly' description="Click this link to log in. It's magic!" />
|
||||
</>
|
|
@ -12,7 +12,8 @@ import Role from '../../components/role'
|
|||
|
||||
type ServerPageProps = PageProps & {
|
||||
currentServer: ServerState,
|
||||
view: ViewState
|
||||
view: ViewState,
|
||||
isDiscordBot: boolean
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, { router: { query: { id } } }) => {
|
||||
|
@ -33,13 +34,20 @@ const Hider = styled.div`
|
|||
|
||||
class Server extends React.Component<ServerPageProps> {
|
||||
static async getInitialProps (ctx: *, rpc: *, router: *) {
|
||||
const isDiscordBot = ctx.req.headers['user-agent'].includes('Discordbot')
|
||||
if (ctx.user == null) {
|
||||
redirect(ctx, `/auth/login?r=${router.asPath}`)
|
||||
if (!isDiscordBot) {
|
||||
redirect(ctx, `/auth/login?r=${router.asPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.robots = 'NOINDEX, NOFOLLOW'
|
||||
await ctx.store.dispatch(fetchServerIfNeed(router.query.id, rpc))
|
||||
await ctx.store.dispatch(renderRoles(router.query.id))
|
||||
|
||||
if (!isDiscordBot) {
|
||||
await ctx.store.dispatch(renderRoles(router.query.id))
|
||||
}
|
||||
return { isDiscordBot }
|
||||
}
|
||||
|
||||
async componentDidMount () {
|
||||
|
@ -58,19 +66,28 @@ class Server extends React.Component<ServerPageProps> {
|
|||
}
|
||||
}
|
||||
|
||||
renderSocial () {
|
||||
const { currentServer } = this.props
|
||||
return <SocialCards title={`${currentServer.server.name} on Roleypoly`} description='Manage your roles here.' />
|
||||
}
|
||||
|
||||
render () {
|
||||
const { currentServer, view } = this.props
|
||||
const { isDiscordBot, currentServer, view } = this.props
|
||||
// console.log({ currentServer })
|
||||
if (currentServer == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (isDiscordBot) {
|
||||
return this.renderSocial()
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title key='title'>{currentServer.server.name} - Roleypoly</title>
|
||||
</Head>
|
||||
<SocialCards title={`${currentServer.server.name} on Roleypoly`} />
|
||||
{ this.renderSocial() }
|
||||
hello <span style={{ color: currentServer.gm.color }}>{currentServer.gm.nickname}</span> on {currentServer.server.name} ({ view.dirty ? 'dirty' : 'clean' })
|
||||
<Hider visible={true || currentServer.id !== null}>
|
||||
{ !view.invalidated && view.categories.map(c => <Category key={c.id}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue