Improve settings UI

This commit is contained in:
Yuya Ochiai
2016-09-12 00:18:09 +09:00
parent 3be2c3facb
commit 7f23c496a2
2 changed files with 47 additions and 75 deletions

View File

@@ -9,7 +9,7 @@ const settings = require('../common/settings');
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const {Grid, Row, Col, Input, Button, ListGroup, ListGroupItem, Glyphicon, HelpBlock} = require('react-bootstrap'); const {Grid, Row, Col, Input, Button, ListGroup, ListGroupItem, Glyphicon, HelpBlock, Navbar, Nav} = require('react-bootstrap');
var AutoLaunch = require('auto-launch'); var AutoLaunch = require('auto-launch');
@@ -140,10 +140,10 @@ var SettingsPage = React.createClass({
showAddTeamForm: !this.state.showAddTeamForm showAddTeamForm: !this.state.showAddTeamForm
}); });
}, },
handleFlashWindowSetting: function(item) { handleFlashWindow: function() {
this.setState({ this.setState({
notifications: { notifications: {
flashWindow: item.state flashWindow: this.refs.flashWindow.getChecked() ? 2 : 0
} }
}); });
}, },
@@ -199,78 +199,54 @@ var SettingsPage = React.createClass({
checked={ this.state.showUnreadBadge } onChange={ this.handleShowUnreadBadge } />); checked={ this.state.showUnreadBadge } onChange={ this.handleShowUnreadBadge } />);
} }
if (process.platform === 'win32' || process.platform === 'linux') {
options.push(<Input key="flashWindow" id="inputflashWindow" ref="flashWindow" type="checkbox" label="Flash the taskbar icon when a new message is received." checked={ this.state.notifications.flashWindow === 2 }
onChange={ this.handleFlashWindow } />);
}
var options_row = (options.length > 0) ? ( var options_row = (options.length > 0) ? (
<Row> <Row>
<Col md={ 12 }> <Col md={ 12 }>
<h2>Options</h2> <h2>App options</h2>
{ options } { options }
</Col> </Col>
</Row> </Row>
) : null; ) : null;
var notifications_row = null;
if (process.platform === 'win32' || process.platform === 'linux') {
var notificationSettings = [
{
label: 'Never',
state: 0
},
/* ToDo: Idle isn't implemented yet
{
label: 'Only when idle (after 10 seconds)',
state: 1
},*/
{
label: 'Always',
state: 2
}
];
var that = this;
var notificationElements = notificationSettings.map(function(item) {
var boundClick = that.handleFlashWindowSetting.bind(that, item);
return (
<Input key={ "flashWindow" + item.state } name="handleFlashWindow" ref={ "flashWindow" + item.state } type="radio" label={ item.label } value={ item.state } onChange={ boundClick }
checked={ that.state.notifications.flashWindow == item.state ? "checked" : "" } />
);
});
notifications_row = (
<Row id="notificationsRow">
<Col md={ 12 }>
<h3>Notifications</h3> Flash the taskbar icon when a new message is received.
{ notificationElements }
</Col>
</Row>
);
}
return ( return (
<Grid className="settingsPage"> <div>
<Row> <Navbar className="navbar-fixed-top">
<Col xs={ 4 } sm={ 2 } md={ 2 } lg={ 1 }> <Navbar.Header>
<h2>Teams</h2> <h1>Settings</h1>
</Col> </Navbar.Header>
<Col xs={ 8 } sm={ 10 } md={ 10 } lg={ 11 }> </Navbar>
<Button bsSize="small" style={ { marginTop: 20 } } onClick={ this.toggleShowTeamForm }> <Grid className="settingsPage" style={ { 'padding-top': '70px' } }>
<Glyphicon glyph="plus" /> <Row>
</Button> <Col md={ 10 } xs={ 8 }>
</Col> <h2>Team Management</h2>
</Row> </Col>
{ teams_row } <Col md={ 2 } xs={ 4 }>
{ options_row } <p className="text-right"><a href="#" onClick={ this.toggleShowTeamForm }> Add new team</a></p>
{ notifications_row } </Col>
<div> </Row>
<hr /> { teams_row }
</div> { options_row }
<Row> <div>
<Col md={ 12 }> <hr />
<Button id="btnCancel" onClick={ this.handleCancel }>Cancel</Button> </div>
{ ' ' } <Row>
<Button id="btnSave" bsStyle="primary" onClick={ this.handleSave } disabled={ this.state.teams.length === 0 }>Save</Button> <Col md={ 12 }>
</Col> </Col>
</Row> </Row>
</Grid> </Grid>
<Navbar className="navbar-fixed-bottom">
<Nav className="navbar-right">
<button id="btnCancel" className="btn navbar-btn" onClick={ this.handleCancel }>Cancel</button>
{ ' ' }
<button id="btnSave" className="btn btn-primary navbar-btn" bsStyle="primary" onClick={ this.handleSave } disabled={ this.state.teams.length === 0 }>Save</button>
</Nav>
</Navbar>
</div>
); );
} }
}); });
@@ -380,13 +356,9 @@ var TeamListItem = React.createClass({
</p> </p>
</div> </div>
<div className="pull-right"> <div className="pull-right">
<Button bsSize="xsmall" onClick={ this.handleTeamEditing }> <small><a hre="#" onClick={ this.handleTeamEditing }>Edit</a></small>
<Glyphicon glyph="pencil" /> { ' - ' }
</Button> <small><a hre="#" onClick={ this.handleTeamRemove }>Remove</a></small>
{ ' ' }
<Button bsSize="xsmall" onClick={ this.handleTeamRemove }>
<Glyphicon glyph="remove" />
</Button>
</div> </div>
</div> </div>
); );

View File

@@ -171,13 +171,13 @@ describe('browser/settings.html', function() {
}); });
}); });
describe('Notifications', function() { describe('Flash taskbar icon on new messages', function() {
it('should appear on win32 and linux', function() { it('should appear on win32 and linux', function() {
const expected = (process.platform === 'win32' || process.platform === 'linux'); const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client return this.app.client
.loadSettingsPage() .loadSettingsPage()
.isExisting('#notificationsRow').should.eventually.equal(expected) .isExisting('#inputflashWindow').should.eventually.equal(expected)
}); });
}); });