-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c99ab5
commit 555f3fc
Showing
17 changed files
with
261 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SLACK_WEBHOOK=https://hooks.slack.com/123/456/789 | ||
SLACK_LOG_WEBHOOK=https://hooks.slack.com/123/456/789 | ||
RASPBERRY=0|1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ images/* | |
|
||
.DS_Store | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import withSocket from '@wrappers/withSocket' | ||
|
||
class ActionButton extends Component { | ||
_onClick(message) { | ||
this.props.socket.emit(message) | ||
} | ||
|
||
render() { | ||
const { text, socketAction } = this.props | ||
|
||
return ( | ||
<a href='#' onClick={() => this._onClick(socketAction)}>{text}</a> | ||
) | ||
} | ||
} | ||
|
||
ActionButton.propTypes = { | ||
text: PropTypes.string.isRequired, | ||
socketAction: PropTypes.string.isRequired, | ||
socket: PropTypes.shape({ | ||
emit: PropTypes.func.isRequired | ||
}).isRequired | ||
} | ||
|
||
export default withSocket(ActionButton) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import ActionButton from '@components/admin-panel/ActionButton' | ||
import withSocket from '@wrappers/withSocket' | ||
import '@styles/admin_panel' | ||
|
||
class AdminPanel extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { active: false } | ||
this._setActive = this._setActive.bind(this) | ||
} | ||
|
||
componentDidMount() { | ||
this.props.socket.on('SET_ADMIN_PANEL_ACTIVE', this._setActive) | ||
} | ||
|
||
_setActive(value) { | ||
this.setState({ active: value }) | ||
} | ||
|
||
_getWrapperClass(active) { | ||
const classes = ['admin-panel'] | ||
if (active) { classes.push('active') } | ||
return classes.join(' ') | ||
} | ||
|
||
render() { | ||
const { active } = this.state | ||
|
||
return ( | ||
<div className={this._getWrapperClass(active)}> | ||
<div className='admin-panel__actions'> | ||
<ActionButton text='Reboot' socketAction='@admin/REBOOT' /> | ||
<ActionButton text='Shutdown' socketAction='@admin/SHUTDOWN' /> | ||
<ActionButton text='Trigger servo' socketAction='@admin/TRIGGER_SERVO' /> | ||
<a className='close' onClick={() => this._setActive(false)}> | ||
Close | ||
</a> | ||
</div> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
AdminPanel.propTypes = { | ||
socket: PropTypes.shape({ | ||
on: PropTypes.func.isRequired | ||
}).isRequired | ||
} | ||
|
||
export default withSocket(AdminPanel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.admin-panel { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
z-index: 10; | ||
padding: 15px; | ||
box-sizing: border-box; | ||
will-change: top; | ||
transition: top 0.6s cubic-bezier(0.4, 0.2, 0, 1); | ||
top: -100%; | ||
background: #30373f; | ||
|
||
&.active { | ||
top: 0%; | ||
} | ||
|
||
&__actions { | ||
margin: 0 -10px 20px; | ||
display: flex; | ||
|
||
a { | ||
font-family: Helvetica, sans-serif; | ||
margin: 0 10px 20px; | ||
padding: 0 20px; | ||
background: #cccccc; | ||
border: 1px solid #b1b2b3; | ||
color: #6d6972; | ||
border-radius: 3px; | ||
font-size: 0.8em; | ||
text-transform: uppercase; | ||
line-height: 2.25em; | ||
font-weight: bold; | ||
} | ||
|
||
a, a:hover, a:active, a:focus, a:visited { | ||
text-decoration: none; | ||
} | ||
|
||
a.close { | ||
margin-left: auto; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { Component } from 'react' | ||
import socketIOClient from 'socket.io-client' | ||
|
||
let socket | ||
|
||
export default function withSocket(WrappedComponent) { | ||
class WithSocket extends Component { | ||
constructor(props) { | ||
super(props) | ||
|
||
if (!socket) { | ||
socket = socketIOClient('http://localhost:3000') | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<WrappedComponent socket={socket} {...this.props} /> | ||
) | ||
} | ||
} | ||
|
||
WithSocket.displayName = `WithSocket(${WrappedComponent.name})` | ||
|
||
return WithSocket; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import shell from 'shelljs' | ||
|
||
import raspberryOnly from '../utils/raspberryOnly' | ||
|
||
let servo | ||
|
||
raspberryOnly(() => { | ||
servo = require('../servo')['default'] | ||
}) | ||
|
||
export default (client) => { | ||
client.on('@admin/REBOOT', () => { | ||
raspberryOnly(() => { | ||
shell.exec('sudo reboot') | ||
client.emit('SET_ADMIN_PANEL_ACTIVE', false); | ||
}) | ||
}) | ||
|
||
client.on('@admin/SHUTDOWN', () => { | ||
raspberryOnly(() => { | ||
shell.exec('sudo shutdown -P now') | ||
client.emit('SET_ADMIN_PANEL_ACTIVE', false); | ||
}) | ||
}) | ||
|
||
client.on('@admin/TRIGGER_SERVO', () => { | ||
raspberryOnly(() => { | ||
servo.move() | ||
client.emit('SET_ADMIN_PANEL_ACTIVE', false); | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import raspberryOnly from '../utils/raspberryOnly' | ||
|
||
let servo | ||
|
||
raspberryOnly(() => { | ||
servo = require('../servo') | ||
}) | ||
|
||
export default (result, user) => { | ||
if (result.win) { | ||
raspberryOnly(() => { | ||
if (result.cashPrize) { servo.move() } | ||
}) | ||
slack.post(user.mention, result.icon, result.cashPrize ? '$$$' : '2 Kudos!') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ const USERS = { | |
5501512322897: { | ||
mention: 'czana', | ||
email: '[email protected]', | ||
admin: true | ||
}, | ||
4402038631408: { | ||
mention: 'bart', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require('dotenv').config() | ||
|
||
export default (theFunction) => { | ||
if (process.env.RASPBERRY === '1') { | ||
theFunction() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters