Skip to content

Commit

Permalink
Move Settings to React
Browse files Browse the repository at this point in the history
  • Loading branch information
rob0rt committed Oct 14, 2015
1 parent 9d59e46 commit 56ec5ce
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion controllers/MembersNewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static function getPath(): string {

public static function get(): :xhp {
$members = new Vector(DB::query("SELECT * FROM users ORDER BY created ASC"));

return
<x:js-scope>
<nucleus:members-table members={$members} />
Expand Down
24 changes: 7 additions & 17 deletions controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,14 @@ public static function getConfig(): ControllerConfig {
}

public static function get(): :xhp {
$applications_open = Settings::get('applications_open');
$settings = Map {
'applications_open' => Settings::get('applications_open'),
};

return
<div class="col-md-6 col-md-offset-3">
<form class="form" action="/settings" method="post">
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="applications_disabled" checked={!$applications_open}/> Disable Applications
</label>
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary pull-right">Save</button>
</form>
</div>;
<x:js-scope>
<nucleus:settings settings={$settings} />
</x:js-scope>;
}

public static function post(): void {
Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gulp.task('build', function () {
});

b.require('./react/MembersTable.js', { expose: 'MembersTable' });
b.require('./react/Settings.js', { expose: 'Settings' });
b.require('xhpjs');

return b.bundle()
Expand Down
30 changes: 30 additions & 0 deletions react/Settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var React = require('react');

class Settings extends React.Component {
render() {
return (
<div className="col-md-6 col-md-offset-3">
<form className="form" action="/settings" method="post">
<div className="panel panel-default">
<div className="panel-body">
<div className="form-group">
<div className="checkbox">
<label>
<input type="checkbox" name="applications_disabled" checked={!this.props.settings.applications_open}/> Disable Applications
</label>
</div>
</div>
</div>
</div>
<button type="submit" className="btn btn-primary pull-right">Save</button>
</form>
</div>
);
}
}

Settings.propTypes = {
members: React.PropTypes.array,
};

module.exports = Settings;
19 changes: 19 additions & 0 deletions views/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?hh // strict

final class :nucleus:settings extends :x:element {
use XHPHelpers;
use XHPReact;

attribute
:xhp:html-element,
Map<string, bool> settings @required;

protected function render(): XHPRoot {
$this->constructReactInstance(
'Settings',
Map {'settings' => $this->:settings }
);

return <div id={$this->getID()} />;
}
}

0 comments on commit 56ec5ce

Please sign in to comment.