mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 02:19:08 +00:00
sync
This commit is contained in:
parent
13cd3bd4a0
commit
52cb96baa3
43 changed files with 3257 additions and 1072 deletions
65
UI/src/components/role-picker/index.js
Normal file
65
UI/src/components/role-picker/index.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
import React, { Component } from 'react'
|
||||
import superagent from 'superagent'
|
||||
import './RolePicker.sass'
|
||||
|
||||
import Role from '../role'
|
||||
|
||||
class RolePicker extends Component {
|
||||
state = {
|
||||
roles: [],
|
||||
categories: {},
|
||||
hidden: true,
|
||||
serverMessage: `Hey there. This is a cool UI you can pick your roles from. If you have any questions, ask the mods on Discord!`
|
||||
}
|
||||
|
||||
async componentDidUpdate (prevProps) {
|
||||
if (prevProps.match.params.server !== this.props.match.params.server) {
|
||||
this.setState({ hidden: true })
|
||||
setTimeout(async () => {
|
||||
this.setState({ roles: [] })
|
||||
this.setState({ roles: await this.getRoles(this.props.match.params.server), hidden: false })
|
||||
}, 350)
|
||||
}
|
||||
}
|
||||
|
||||
async componentWillMount () {
|
||||
this.setState({ roles: await this.getRoles(this.props.match.params.server), hidden: false })
|
||||
}
|
||||
|
||||
async getRoles (id) {
|
||||
const rsp = await superagent.get(`/api/server/${id}`)
|
||||
return rsp.body//.map(r => { r.selected = false; return r })
|
||||
}
|
||||
|
||||
onChange = k => (newVal, oldVal) => {
|
||||
this.setState((prevState) => {
|
||||
return { roles: prevState.roles.map(r => {
|
||||
if (r.id === k) {
|
||||
r.selected = newVal
|
||||
}
|
||||
|
||||
return r
|
||||
})}
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
return <div className={`role-picker ${(this.state.hidden) ? 'hidden' : ''}`}>
|
||||
<section>
|
||||
<h3>Server Message</h3>
|
||||
<p>{this.state.serverMessage}</p>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Roles</h3>
|
||||
{
|
||||
this.state.roles.map((r, k) => {
|
||||
|
||||
return <Role key={k} role={r} onToggle={this.onChange(r.id)} />
|
||||
})
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
export default RolePicker
|
Loading…
Add table
Add a link
Reference in a new issue