Skip to content

Instantly share code, notes, and snippets.

@ryanpedersen42
Created September 1, 2019 21:39
Show Gist options
  • Save ryanpedersen42/3cb117d641c96fb5091522bdbaacc9e7 to your computer and use it in GitHub Desktop.
Save ryanpedersen42/3cb117d641c96fb5091522bdbaacc9e7 to your computer and use it in GitHub Desktop.
Third App.jsx Iteration (Add News Space)
// src/App.jsx
// ...imports removed for brevity
class App extends Component {
constructor(props) {
super(props);
this.state = {
box: null,
ethAddress: '',
userProfile: {},
isAppReady: false,
selectedSpace: '',
dappStorage: [],
newSpaceName: '', //*NEW* addition
};
}
// ...functions removed for brevity
// *NEW* functions to handle new space creation
// name for new space
handleNameChange = (name) => {
this.setState({newSpaceName: name});
}
// call openSpace() with name for new space
createNewSpace = async () => {
const { inputKey, box } = this.state;
try {
await box.openSpace(inputKey);
} catch(err) {
console.log(err);
}
}
render() {
const { isAppReady, ethAddress, box, spaceOptions, selectedSpace } = this.state;
return (
<div className='App'>
{isAppReady && (<Fragment>
<Switch>
{/* auth route removed for brevity */}
<Route
exact
path='/main'
render={() => (
<MainPage
//state
ethAddress={ethAddress}
spaceOptions={spaceOptions}
selectedSpace={selectedSpace}
//functions
handleNameChange={this.handleNameChange}
createNewSpace={this.createNewSpace}
changeSelectedSpace={this.changeSelectedSpace}
/>
)}
/>
</Switch>
</Fragment>)}
</div>
);
}
}
export default withRouter(App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment