Last active
September 2, 2019 02:46
-
-
Save ryanpedersen42/d8fbbc59b2dd49dfb77e82f160a3826f to your computer and use it in GitHub Desktop.
CreateNewSpace App.jsx
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
// 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