Add store for dapps state (#3211)

* Add mobx

* Use mobx store for dapps

* Cleanup hidden reads

* Remove (now) unused hidden.js

* _ denotes internal functions

* s/visibleApps/visible/

* AddDapps now use the mobx store as well

* Move modalOpen state to store

* Simplify

* Complete master merge

* Remove extra indirection

* Remove unneeded check

* Readability improvements

* Remove final debug info
This commit is contained in:
Jaco Greeff
2016-11-07 15:22:46 +01:00
committed by Gav Wood
parent 834c0703fe
commit f0054aa201
8 changed files with 289 additions and 357 deletions

View File

@@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { observer } from 'mobx-react';
import DoneIcon from 'material-ui/svg-icons/action/done';
import { List, ListItem } from 'material-ui/List';
import Checkbox from 'material-ui/Checkbox';
@@ -23,57 +24,67 @@ import { Modal, Button } from '../../../ui';
import styles from './AddDapps.css';
@observer
export default class AddDapps extends Component {
static propTypes = {
available: PropTypes.array.isRequired,
hidden: PropTypes.array.isRequired,
open: PropTypes.bool.isRequired,
onHideApp: PropTypes.func.isRequired,
onShowApp: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired
store: PropTypes.object.isRequired
};
render () {
const { onClose, open, available } = this.props;
const { store } = this.props;
if (!store.modalOpen) {
return null;
}
return (
<Modal
compact
title='visible applications'
actions={ [
<Button label={ 'Done' } key='done' onClick={ onClose } icon={ <DoneIcon /> } />
<Button
label={ 'Done' }
key='done'
onClick={ store.closeModal }
icon={ <DoneIcon /> }
/>
] }
visible={ open }
visible
scroll>
<List>
{ available.map(this.renderApp) }
{ store.apps.map(this.renderApp) }
</List>
</Modal>
);
}
renderApp = (app) => {
const { hidden, onHideApp, onShowApp } = this.props;
const isHidden = hidden.includes(app.id);
const description = (
<div className={ styles.description }>
{ app.description }
</div>
);
const { store } = this.props;
const isHidden = store.hidden.includes(app.id);
const onCheck = () => {
if (isHidden) {
onShowApp(app.id);
store.showApp(app.id);
} else {
onHideApp(app.id);
store.hideApp(app.id);
}
};
return (
<ListItem
key={ app.id }
leftCheckbox={ <Checkbox checked={ !isHidden } onCheck={ onCheck } /> }
leftCheckbox={
<Checkbox
checked={ !isHidden }
onCheck={ onCheck }
/>
}
primaryText={ app.name }
secondaryText={ description } />
secondaryText={
<div className={ styles.description }>
{ app.description }
</div>
}
/>
);
}
}