Browse Source

LoadingContainer improvements (2)

develop
Ezerous 4 years ago
parent
commit
e94fa5588a
  1. 16
      packages/concordia-app/src/assets/css/loading-component.css
  2. 0
      packages/concordia-app/src/assets/images/app_logo.png
  3. 73
      packages/concordia-app/src/components/LoadingComponent.jsx
  4. 211
      packages/concordia-app/src/components/LoadingContainer.jsx
  5. 1
      packages/concordia-app/src/options/drizzleOptions.js
  6. 4
      packages/concordia-app/src/orbit/orbitUtils.js
  7. 6
      packages/concordia-app/src/redux/sagas/orbitSaga.js

16
packages/concordia-app/src/assets/css/loading-container.css → packages/concordia-app/src/assets/css/loading-component.css

@ -1,7 +1,11 @@
html { body {
overflow: hidden; overflow: hidden;
} }
ul {
list-style-position: inside;
}
.loading-screen { .loading-screen {
text-align: center; text-align: center;
font-size: large; font-size: large;
@ -12,10 +16,12 @@ html {
height: 12em; height: 12em;
} }
ul { .ui.container {
list-style-position: inside; height: 26em;
} }
.bar { .ui.progress {
margin-top: 5em; width: 40vw;
margin-left: auto !important;
margin-right: auto !important;
} }

0
packages/concordia-app/src/assets/images/logo.png → packages/concordia-app/src/assets/images/app_logo.png

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 216 KiB

73
packages/concordia-app/src/components/LoadingComponent.jsx

@ -0,0 +1,73 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Container, Progress } from 'semantic-ui-react';
// CSS
import '../assets/css/loading-component.css';
// Images
import ethereum_logo from '../assets/images/ethereum_logo.svg';
import ipfs_logo from '../assets/images/ipfs_logo.svg';
import orbitdb_logo from '../assets/images/orbitdb_logo.png';
import app_logo from '../assets/images/app_logo.png';
class LoadingComponent extends Component {
render(){
const { image_type, message_list, progress_type } = this.props ;
let imageSrc, imageAlt, listItems, indicating, error;
if (image_type === "ethereum"){
imageSrc = ethereum_logo;
imageAlt = "ethereum_logo";
}
else if (image_type === "ipfs"){
imageSrc = ipfs_logo;
imageAlt = "ipfs_logo";
}
else if (image_type === "orbit"){
imageSrc = orbitdb_logo;
imageAlt = "orbitdb_logo";
}
else if (image_type === "app"){
imageSrc = app_logo;
imageAlt = "app_logo";
}
if(progress_type === "indicating")
indicating = true;
else if(progress_type === "error")
error = true;
if(message_list){
listItems = message_list.map((listItem) =>
<li>{listItem}</li>
);
}
const list = message_list ? <ul>{listItems}</ul> : '';
return(
<main className="loading-screen">
<Container>
<img src={imageSrc} alt={imageAlt} className="loading-img" />
<p><strong>{this.props.title}</strong></p>
<p>{this.props.message}</p>
{list}
</Container>
<Progress percent={this.props.progress} size='small' indicating={indicating} error={error}/>
</main>
);
}
}
LoadingComponent.propTypes = {
title: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
message_list: PropTypes.arrayOf(PropTypes.string),
image_type: PropTypes.string.isRequired,
progress: PropTypes.number.isRequired,
progress_type: PropTypes.string.isRequired,
};
export default LoadingComponent;

211
packages/concordia-app/src/components/LoadingContainer.jsx

@ -1,164 +1,143 @@
import React, { Children, Component } from 'react'; import React, { Children, Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Progress } from 'semantic-ui-react' import { Container, Progress } from 'semantic-ui-react'
import { breezeConstants } from '@ezerous/breeze'
import LoadingComponent from './LoadingComponent';
// CSS // CSS
import '../assets/css/loading-container.css'; import '../assets/css/loading-component.css';
// Images // Images
import ethereum_logo from '../assets/images/ethereum_logo.svg'; import ethereum_logo from '../assets/images/ethereum_logo.svg';
import ipfs_logo from '../assets/images/ipfs_logo.svg'; import ipfs_logo from '../assets/images/ipfs_logo.svg';
import orbitdb_logo from '../assets/images/orbitdb_logo.png'; import orbitdb_logo from '../assets/images/orbitdb_logo.png';
import logo from '../assets/images/logo.png'; import logo from '../assets/images/app_logo.png';
class LoadingContainer extends Component { class LoadingContainer extends Component {
render() { render() {
if (this.props.web3.status === 'initializing') { if ((this.props.web3.status === 'initializing' || !this.props.web3.networkId)
return ( && !this.props.web3.networkFailed) {
<main className="loading-screen"> return <LoadingComponent
<div className="ui container"> title="Connecting to the Ethereum network..."
<img src={ethereum_logo} alt="ethereum_logo" className="loading-img" /> message="Please make sure to unlock MetaMask."
<p><strong>Connecting to the Ethereum network...</strong></p> image_type="ethereum"
<p>Please make sure to unlock MetaMask.</p> progress={20}
<Progress percent="20" size='tiny' active /> progress_type="indicating"
</div> />
</main>
);
} }
if (this.props.web3.status === 'failed' || this.props.web3.networkFailed) { if (this.props.web3.status === 'failed' || this.props.web3.networkFailed) {
return ( return <LoadingComponent
<main className="loading-screen"> title="No connection to the Ethereum network!"
<div className="ui container"> message="Please make sure that:"
<img src={ethereum_logo} alt="ethereum_logo" className="loading-img" /> message_list={['MetaMask is unlocked and pointed to the correct, available network',
<p><strong>No connection to the Ethereum network!</strong></p> 'The app has been granted the right to connect to your account']}
Please make sure that: image_type="ethereum"
<ul> progress={20}
<li>MetaMask is unlocked and pointed to the correct network</li> progress_type="error"
<li>The app has been granted the right to connect to your account</li> />
</ul>
<Progress percent="20" size='tiny' error />
</div>
</main>
);
} }
if (this.props.web3.status === 'initialized' && this.props.web3.accountsFailed) { if (this.props.web3.status === 'initialized' && this.props.web3.accountsFailed) {
return ( return <LoadingComponent
<main className="loading-screen"> title="We can't find any Ethereum accounts!"
<div className="ui container"> message="Please make sure that MetaMask is unlocked."
<img src={ethereum_logo} alt="ethereum_logo" className="loading-img" /> image_type="ethereum"
<p><strong>We can't find any Ethereum accounts!</strong></p> progress={20}
<p>Please make sure that MetaMask is unlocked.</p> progress_type="error"
<Progress percent="20" size='tiny' error /> />
</div>
</main>
);
} }
if (!this.props.contractInitialized) { if (this.props.drizzleStatus.initializing
return ( || (!this.props.drizzleStatus.failed && !this.props.contractInitialized && this.props.contractDeployed )){
<main className="loading-screen"> return <LoadingComponent
<div className="ui container"> title="Initializing contracts..."
<img src={ethereum_logo} alt="ethereum_logo" className="loading-img" /> message=""
<p><strong>Initializing contracts...</strong></p><p/> image_type="ethereum"
<Progress percent="40" size='tiny' active /> progress={40}
</div> progress_type="indicating"
</main> />
);
} }
if (!this.props.contractDeployed) { if (!this.props.contractDeployed) {
return ( return <LoadingComponent
<main className="loading-screen"> title="No contracts found on the current network!"
<div className="ui container"> message="Please make sure that you are connected to the correct network and the contracts are deployed."
<img src={ethereum_logo} alt="ethereum_logo" className="loading-img" /> image_type="ethereum"
<p><strong>No contracts found on the current network!</strong></p> progress={40}
<p>Please make sure that you are connected to the correct network progress_type="error"
and the contracts are deployed.</p> />
<Progress percent="40" size='tiny' error />
</div>
</main>
);
} }
if (!this.props.ipfsInitialized && !this.props.ipfsFailed) { if (this.props.ipfsStatus === breezeConstants.STATUS_INITIALIZING) {
return ( return <LoadingComponent
<main className="loading-screen"> title="Initializing IPFS..."
<div className="ui container"> message=""
<img src={ipfs_logo} alt="ipfs_logo" className="loading-img" /> image_type="ipfs"
<p><strong>Initializing IPFS...</strong></p><p/> progress={60}
<Progress percent="60" size='tiny' active /> progress_type="indicating"
</div> />
</main>
);
} }
if (this.props.ipfsFailed) { if (this.props.ipfsStatus === breezeConstants.STATUS_FAILED) {
return ( return <LoadingComponent
<main className="loading-screen"> title="IPFS initialization failed!"
<div className="ui container"> message=""
<img src={ipfs_logo} alt="ipfs_logo" className="loading-img" /> image_type="ipfs"
<p><strong>IPFS initialization failed!</strong></p><p/> progress={60}
<Progress percent="60" size='tiny' error /> progress_type="error"
</div> />
</main>
);
} }
if (!this.props.orbitInitialized && !this.props.orbitFailed) { if (this.props.orbitStatus === breezeConstants.STATUS_INITIALIZING) {
const message = process.env.NODE_ENV === 'development' const message = process.env.NODE_ENV === 'development'
? 'If needed, please sign the transaction in MetaMask to create the databases.' ? 'If needed, please sign the transaction in MetaMask to create the databases.'
: 'Please sign the transaction in MetaMask to create the databases.'; : 'Please sign the transaction in MetaMask to create the databases.';
return ( return <LoadingComponent
<main className="loading-screen"> title="Preparing OrbitDB..."
<div className="ui container"> message={message}
<img src={orbitdb_logo} alt="orbitdb_logo" className="loading-img" /> image_type="orbit"
<p><strong>Preparing OrbitDB...</strong></p> progress={80}
<p>{message}</p> progress_type="indicating"
<Progress percent="80" size='tiny' active /> />
</div> }
</main>
); if (this.props.orbitStatus === breezeConstants.STATUS_FAILED) {
return <LoadingComponent
title="OrbitDB initialization failed!"
message=""
image_type="orbit"
progress={80}
progress_type="error"
/>
} }
if (this.props.orbitFailed) { // Just in case our redux logic changes in the future
return ( if (!this.props.drizzleStatus.initialized){
<main className="loading-screen"> return <LoadingComponent
<div className="ui container"> title="Loading dapp..."
<img src={orbitdb_logo} alt="orbitdb_logo" className="loading-img" /> message=""
<p><strong>OrbitDB initialization failed!</strong></p><p/> image_type="app"
<Progress percent="80" size='tiny' error /> progress={90}
</div> progress_type="error"
</main> />
);
} }
if (this.props.drizzleStatus.initialized) return Children.only(this.props.children); return Children.only(this.props.children);
return (
<main className="loading-screen">
<div className="ui container">
<img src={logo} alt="app_logo" className="loading-img" />
<p><strong>Loading dapp...</strong></p><p/>
<Progress percent="90" size='tiny' error />
</div>
</main>
);
} }
} }
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
accounts: state.accounts,
drizzleStatus: state.drizzleStatus, drizzleStatus: state.drizzleStatus,
breezeStatus: state.breezeStatus, breezeStatus: state.breezeStatus,
ipfsStatus: state.ipfs.status,
orbitStatus: state.orbit.status,
web3: state.web3, web3: state.web3,
accounts: state.accounts,
contractInitialized: state.contracts.Forum.initialized, contractInitialized: state.contracts.Forum.initialized,
contractDeployed: state.contracts.Forum.deployed, contractDeployed: state.contracts.Forum.deployed,
ipfsInitialized: state.ipfs.initialized,
ipfsFailed: state.ipfs.failed,
orbitInitialized: state.orbit.initialized,
orbitFailed: state.orbit.failed
}); });
export default connect(mapStateToProps)(LoadingContainer); export default connect(mapStateToProps)(LoadingContainer);

1
packages/concordia-app/src/options/drizzleOptions.js

@ -10,6 +10,7 @@ const drizzleOptions = {
events: { events: {
Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated'] Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated']
}, },
reloadWindowOnNetworkChange: true,
reloadWindowOnAccountChange: true // We need it to reinitialize breeze and create new Orbit databases reloadWindowOnAccountChange: true // We need it to reinitialize breeze and create new Orbit databases
}; };

4
packages/concordia-app/src/orbit/orbitUtils.js

@ -5,7 +5,3 @@ export async function determineDBAddress({orbit, dbName, type, identityId}) {
})).root; })).root;
return `/orbitdb/${ipfsMultihash}/${dbName}`; return `/orbitdb/${ipfsMultihash}/${dbName}`;
} }

6
packages/concordia-app/src/redux/sagas/orbitSaga.js

@ -11,12 +11,12 @@ export function * initOrbitDatabases (action) {
function * orbitSaga () { function * orbitSaga () {
// Not sure which will come first // Not sure which will come first
const res = yield all([ const res = yield all([
take(drizzleActions.drizzle.DRIZZLE_INITIALIZED),
take(breezeActions.breeze.BREEZE_INITIALIZED), take(breezeActions.breeze.BREEZE_INITIALIZED),
take(action => action.type === drizzleActions.account.ACCOUNTS_FETCHED take(action => action.type === drizzleActions.account.ACCOUNTS_FETCHED)
&& action.accounts.length > 0)
]); ]);
yield initOrbitDatabases({breeze:res[0].breeze, account: res[1].accounts[0]}); yield initOrbitDatabases({breeze:res[1].breeze, account: res[2].accounts[0]});
} }
export default orbitSaga export default orbitSaga

Loading…
Cancel
Save