Skip to content

Commit

Permalink
Update packages and improve dashboard SEO. Cleanup schema.
Browse files Browse the repository at this point in the history
Improve SEO and add option to select channels from list to dashboard.
  • Loading branch information
retrixe committed Nov 8, 2018
1 parent 3c65e6e commit e96faaf
Show file tree
Hide file tree
Showing 8 changed files with 677 additions and 677 deletions.
39 changes: 22 additions & 17 deletions components/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import { gql } from 'apollo-boost'

/* eslint-disable quotes, no-multi-str, no-undef */
interface Props {
data: Array<{ perms: boolean, icon: string, serverId: string, name: string }>,
data: Array<{
perms: boolean, icon: string, serverId: string, name: string, channels: string[]
}>,
token: string
}
interface State {
selected: boolean | { perms: boolean, icon: string, serverId: string, name: string }
selected: boolean | {
perms: boolean, icon: string, serverId: string, name: string, channels: string[]
}
}
class DashboardIndex extends React.Component<Props, State> {
constructor (props) {
Expand All @@ -41,20 +45,21 @@ query getServerSettings($server: String!, $token: String!) {
`
let settings
if (!this.state.selected) {
settings = <List>{this.props.data.map(element => {
let nameOfServer = element.name ? element.name : ''
if (nameOfServer.length >= 32) nameOfServer = element.name.substr(0, 29) + '...'
return (
<ListItem disabled={!element.perms}
divider button key={element.serverId} onClick={() => this.setState({ selected: element })}>
{element.icon === 'no icon'
? ''
: <Avatar src={element.icon} />
}
<ListItemText primary={nameOfServer} secondary={element.serverId} />
</ListItem>
)
})}</List>
settings = (
<List>{this.props.data.map(element => {
let nameOfServer = element.name ? element.name : ''
if (nameOfServer.length >= 32) nameOfServer = element.name.substr(0, 29) + '...'
return (
<ListItem
disabled={!element.perms} divider button key={element.serverId}
onClick={() => this.setState({ selected: element })}
>
{element.icon === 'no icon' ? '' : <Avatar src={element.icon} />}
<ListItemText primary={nameOfServer} secondary={element.serverId} />
</ListItem>
)
})}</List>
)
} else if (typeof this.state.selected === 'object') {
const element = this.state.selected
let nameOfServer = element.name
Expand Down Expand Up @@ -90,7 +95,7 @@ query getServerSettings($server: String!, $token: String!) {
refetch={refetch}
data={data.serverSettings}
token={this.props.token}
server={element.serverId}
server={element}
/>
}}
</Query>
Expand Down
22 changes: 13 additions & 9 deletions components/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as React from 'react'
import {
Typography, Button, LinearProgress, Divider, Input, InputLabel, FormGroup, FormControlLabel,
FormControl, FormHelperText, Switch
FormControl, FormHelperText, Switch, Select, MenuItem
} from '@material-ui/core'
import { Mutation } from 'react-apollo'
import { gql } from 'apollo-boost'
// import TextField from 'material-ui/TextField'

/* eslint-disable quotes, no-multi-str, no-undef */
interface Props {
Expand All @@ -17,7 +16,7 @@ interface Props {
}
},
token: string,
server: string,
server: { perms: boolean, icon: string, serverId: string, name: string, channels: string[] },
refetch: Function
}
interface State {
Expand Down Expand Up @@ -69,7 +68,7 @@ mutation variables(
<Mutation mutation={mutation} variables={{
token: this.props.token,
role: this.state.role,
server: this.props.server,
server: this.props.server.serverId,
joinAutorole: this.state.joinAutorole,
joinLeaveMessages: this.state.joinLeaveMessages,
ocrOnSend: this.state.ocrOnSend
Expand Down Expand Up @@ -124,11 +123,16 @@ mutation variables(
<Typography gutterBottom>Ensure the channel name is correct.</Typography>
<FormControl fullWidth>
<InputLabel>Channel Name</InputLabel>
<Input
value={this.state.joinLeaveMessages.channelName} fullWidth
onChange={e => this.setState({ joinLeaveMessages: {
...this.state.joinLeaveMessages, channelName: e.target.value
} })} margin='dense' />
<Select value={this.state.joinLeaveMessages.channelName} fullWidth margin='dense'
onChange={e => this.setState({
joinLeaveMessages: {
...this.state.joinLeaveMessages, channelName: e.target.value
}
})}
>
<MenuItem value=''><em>None</em></MenuItem>
{this.props.server.channels.map(i => (<MenuItem value={i} key={i}>{i}</MenuItem>))}
</Select>
<FormHelperText>Leave blank to disable join/leave messages</FormHelperText>
</FormControl>
<div style={{ height: 10 }} />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@material-ui/icons": "^3.0.1",
"apollo-boost": "^0.1.4",
"eris": "abalabahaha/eris#dev",
"graphql": "https://cdn.discordapp.com/attachments/415150079050252308/498798226166775818/graphql.tgz",
"graphql": "^14.0.2",
"graphql-yoga": "^1.8.5",
"isomorphic-unfetch": "^2.0.0",
"json5": "^0.5.1",
Expand Down
10 changes: 7 additions & 3 deletions pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
} from '@material-ui/core'
import Link from 'next/link'
import fetch from 'isomorphic-unfetch'
import withRoot from '../components/withRoot'
import Dashboard from '../components/dashboard'
import ApolloClient, { gql } from 'apollo-boost'
import { ApolloProvider, Query } from 'react-apollo'
import Dashboard from '../components/dashboard'
import withRoot from '../components/withRoot'

// Apollo Client definition.
const client = new ApolloClient({ uri: `/graphql`, fetchOptions: { fetch } })
Expand All @@ -26,13 +26,17 @@ query getAllCommonServers($token: String!) {
name
perms
icon
channels
}
}
`
return (
<ApolloProvider client={client}>
<>
<title>IveBot</title>
<head>
<title>IveBot</title>
<meta name='Description' content={'IveBot\'s dashboard for managing settings.'} />
</head>
{/* login dialog. */}
<Dialog open={this.state.open} onClose={this.closeDialog}>
<DialogTitle>Log In</DialogTitle>
Expand Down
5 changes: 4 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Index extends React.Component {
render () {
return (
<div style={{ marginRight: 16, marginLeft: 16 }}>
<title>IveBot</title>
<head>
<title>IveBot</title>
<meta name='Description' content='IveBot is a multi-purpose Discord bot.' />
</head>
<AppBar>
<Toolbar>
<Typography variant='title' color='inherit' style={{ flex: 1 }}>IveBot</Typography>
Expand Down
5 changes: 4 additions & 1 deletion server/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
},
getUserInfo: (_: string, { linkToken }: { linkToken: string }) => {
if (ctx.tempDB.link[linkToken]) {
let servers: Array<{ perms: boolean, icon: string, serverId: string, name: string }> = []
let servers: Array<{ /* eslint-disable indent */
perms: boolean, icon: string, serverId: string, name: string, channels: string[]
}> = [] /* eslint-enable indent */
ctx.client.guilds.forEach(server => {
ctx.client.guilds.find(a => a.id === server.id).members.forEach(member => {
if (member.id === ctx.tempDB.link[linkToken]) {
servers.push({
serverId: server.id,
name: server.name,
icon: server.iconURL || 'no icon',
channels: server.channels.filter(i => i.type === 0).map(i => i.name),
perms: host === ctx.tempDB.link[linkToken]
? true : member.permission.has('manageGuild')
})
Expand Down
45 changes: 25 additions & 20 deletions server/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Server specific settings.
type ServerSetting {
# Server ID.
serverId: String!
# If add role is enabled for everyone.
addRoleForAll: Boolean
# If join/leave messages are enabled, and if so, what message and channel.
joinLeaveMessages: JoinLeaveMessages
# If join autorole is enabled, and if so, what role.
joinAutorole: String
# If text recognition on image send is enabled.
ocrOnSend: Boolean
# Joining and leaving servers.
type JoinLeaveMessages {
# Name of channel.
channelName: String
# What to post when joining.
joinMessage: String
# What to post when leaving.
leaveMessage: String
}

# Server type.
Expand All @@ -22,16 +18,22 @@ type Server {
icon: String
# Name of server.
name: String
# Channels in server.
channels: [String]
}

# Joining and leaving servers.
type JoinLeaveMessages {
# Name of channel.
channelName: String
# What to post when joining.
joinMessage: String
# What to post when leaving.
leaveMessage: String
# Server specific settings.
type ServerSetting {
# Server ID.
serverId: String!
# If add role is enabled for everyone.
addRoleForAll: Boolean
# If join/leave messages are enabled, and if so, what message and channel.
joinLeaveMessages: JoinLeaveMessages
# If join autorole is enabled, and if so, what role.
joinAutorole: String
# If text recognition on image send is enabled.
ocrOnSend: Boolean
}

# Enable queries.
Expand Down Expand Up @@ -76,7 +78,10 @@ type Mutation {
editServerSettings(input: EditServerSettingsInput!): ServerSetting!
}

# Final schema.
schema {
# Mutations to modify data.
mutation: Mutation
# Queries to query data.
query: Query
}
Loading

0 comments on commit e96faaf

Please sign in to comment.