mirror of https://gitlab.com/ecentrics/concordia
Apostolos Fanakis
4 years ago
28 changed files with 748 additions and 707 deletions
@ -1,72 +0,0 @@ |
|||||
// Modified version of https://github.com/trufflesuite/drizzle/blob/develop/packages/react-plugin/src/DrizzleContext.js
|
|
||||
import React from "react"; |
|
||||
|
|
||||
const Context = React.createContext(); |
|
||||
|
|
||||
class Provider extends React.Component { |
|
||||
state = { |
|
||||
drizzleState: null, |
|
||||
drizzleInitialized: false, |
|
||||
breezeState: null, |
|
||||
breezeInitialized: false |
|
||||
}; |
|
||||
|
|
||||
componentDidMount() { |
|
||||
const { drizzle, breeze } = this.props; |
|
||||
// subscribe to changes in the store, keep state up-to-date
|
|
||||
this.unsubscribe = drizzle.store.subscribe(() => { |
|
||||
const drizzleState = drizzle.store.getState(); |
|
||||
const breezeState = breeze.store.getState(); |
|
||||
|
|
||||
if (drizzleState.drizzleStatus.initialized) { |
|
||||
this.setState({ |
|
||||
drizzleState, |
|
||||
drizzleInitialized: true |
|
||||
}); |
|
||||
} |
|
||||
if (breezeState.breezeStatus.initialized) { |
|
||||
this.setState({ |
|
||||
breezeState: breezeState, |
|
||||
breezeInitialized: true |
|
||||
}); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
this.unsubscribe = breeze.store.subscribe(() => { |
|
||||
const breezeState = breeze.store.getState(); |
|
||||
if (breezeState.breezeStatus.initialized) { |
|
||||
this.setState({ |
|
||||
breezeState: breezeState, |
|
||||
breezeInitialized: true |
|
||||
}); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
componentWillUnmount() { |
|
||||
this.unsubscribe(); |
|
||||
} |
|
||||
|
|
||||
render() { |
|
||||
return ( |
|
||||
<Context.Provider |
|
||||
value={{ |
|
||||
drizzle: this.props.drizzle, |
|
||||
drizzleState: this.state.drizzleState, |
|
||||
drizzleInitialized: this.state.drizzleInitialized, |
|
||||
breeze: this.props.breeze, |
|
||||
breezeState: this.state.breezeState, |
|
||||
breezeInitialized: this.state.breezeInitialized |
|
||||
}} |
|
||||
> |
|
||||
{this.props.children} |
|
||||
</Context.Provider> |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export default { |
|
||||
Context: Context, |
|
||||
Consumer: Context.Consumer, |
|
||||
Provider |
|
||||
}; |
|
@ -0,0 +1,81 @@ |
|||||
|
// Modified version of https://github.com/trufflesuite/drizzle/blob/develop/packages/react-plugin/src/DrizzleContext.js |
||||
|
import React from 'react'; |
||||
|
|
||||
|
const Context = React.createContext(); |
||||
|
|
||||
|
class Provider extends React.Component { |
||||
|
constructor(props) { |
||||
|
super(props); |
||||
|
|
||||
|
this.state = { |
||||
|
drizzleState: null, |
||||
|
drizzleInitialized: false, |
||||
|
breezeState: null, |
||||
|
breezeInitialized: false, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
componentDidMount() { |
||||
|
const { drizzle, breeze } = this.props; |
||||
|
// subscribe to changes in the store, keep state up-to-date |
||||
|
this.unsubscribe = drizzle.store.subscribe(() => { |
||||
|
const drizzleState = drizzle.store.getState(); |
||||
|
const breezeState = breeze.store.getState(); |
||||
|
|
||||
|
if (drizzleState.drizzleStatus.initialized) { |
||||
|
this.setState({ |
||||
|
drizzleState, |
||||
|
drizzleInitialized: true, |
||||
|
}); |
||||
|
} |
||||
|
if (breezeState.breezeStatus.initialized) { |
||||
|
this.setState({ |
||||
|
breezeState, |
||||
|
breezeInitialized: true, |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
this.unsubscribe = breeze.store.subscribe(() => { |
||||
|
const breezeState = breeze.store.getState(); |
||||
|
if (breezeState.breezeStatus.initialized) { |
||||
|
this.setState({ |
||||
|
breezeState, |
||||
|
breezeInitialized: true, |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
componentWillUnmount() { |
||||
|
this.unsubscribe(); |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
const { |
||||
|
drizzleState, drizzleInitialized, breezeState, breezeInitialized, |
||||
|
} = this.state; |
||||
|
const { drizzle, breeze, children } = this.props; |
||||
|
|
||||
|
return ( |
||||
|
<Context.Provider |
||||
|
value={{ |
||||
|
drizzle, |
||||
|
drizzleState, |
||||
|
drizzleInitialized, |
||||
|
breeze, |
||||
|
breezeState, |
||||
|
breezeInitialized, |
||||
|
}} |
||||
|
> |
||||
|
{children} |
||||
|
</Context.Provider> |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default { |
||||
|
Context, |
||||
|
Consumer: Context.Consumer, |
||||
|
Provider, |
||||
|
}; |
@ -1,19 +1,21 @@ |
|||||
import React, { Component } from 'react'; |
import React from 'react'; |
||||
import PropTypes from 'prop-types'; |
import PropTypes from 'prop-types'; |
||||
|
|
||||
import MenuComponent from './MenuComponent'; |
import MenuComponent from './MenuComponent'; |
||||
|
|
||||
export default class CoreLayout extends Component { |
const CoreLayout = (props) => { |
||||
render() { |
const { children } = props; |
||||
|
|
||||
return ( |
return ( |
||||
<div> |
<div> |
||||
<MenuComponent/> |
<MenuComponent /> |
||||
{this.props.children} |
{children} |
||||
</div> |
</div> |
||||
) |
); |
||||
} |
}; |
||||
} |
|
||||
|
|
||||
CoreLayout.propTypes = { |
CoreLayout.propTypes = { |
||||
children: PropTypes.element.isRequired |
children: PropTypes.element.isRequired, |
||||
}; |
}; |
||||
|
|
||||
|
export default CoreLayout; |
||||
|
@ -1,9 +1,5 @@ |
|||||
import React, { Component } from 'react'; |
import React from 'react'; |
||||
|
|
||||
class HomeContainer extends Component { |
const HomeContainer = () => (<p>TODO: Home Container</p>); |
||||
render() { |
|
||||
return(<p>TODO: Home Container</p>); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export default HomeContainer; |
export default HomeContainer; |
||||
|
@ -1,38 +1,35 @@ |
|||||
import React, { Component } from 'react'; |
import React from 'react'; |
||||
import { withRouter } from "react-router"; |
import { withRouter } from 'react-router'; |
||||
import { Menu } from 'semantic-ui-react'; |
import { Menu } from 'semantic-ui-react'; |
||||
|
|
||||
import AppContext from "./AppContext"; |
import AppContext from './AppContext'; |
||||
|
|
||||
import app_logo from '../assets/images/app_logo.png'; |
import appLogo from '../assets/images/app_logo.png'; |
||||
import SignUpForm from './SignUpForm'; |
import SignUpForm from './SignUpForm'; |
||||
|
|
||||
class MenuComponent extends Component { |
const MenuComponent = (props) => { |
||||
render() { |
const { history: { push } } = props; |
||||
|
|
||||
return ( |
return ( |
||||
<AppContext.Consumer> |
<AppContext.Consumer> |
||||
{context => { |
{() => ( |
||||
return( |
|
||||
<div> |
<div> |
||||
<Menu color='black' inverted> |
<Menu color="black" inverted> |
||||
<Menu.Item |
<Menu.Item |
||||
link |
link |
||||
name='home' |
name="home" |
||||
onClick={() => { this.props.history.push("/"); }} |
onClick={() => { push('/'); }} |
||||
> |
> |
||||
<img src={app_logo} alt="app_logo"/> |
<img src={appLogo} alt="app_logo" /> |
||||
</Menu.Item> |
</Menu.Item> |
||||
|
|
||||
<SignUpForm/> |
<SignUpForm /> |
||||
|
|
||||
</Menu> |
</Menu> |
||||
</div> |
</div> |
||||
) |
)} |
||||
} |
|
||||
} |
|
||||
</AppContext.Consumer> |
</AppContext.Consumer> |
||||
) |
); |
||||
} |
}; |
||||
} |
|
||||
|
|
||||
export default withRouter(MenuComponent); |
export default withRouter(MenuComponent); |
||||
|
@ -1,7 +1,11 @@ |
|||||
// https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#address
|
// https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#address
|
||||
export async function determineDBAddress({orbit, dbName, type, identityId}) { |
async function determineDBAddress({ |
||||
|
orbit, dbName, type, identityId, |
||||
|
}) { |
||||
const ipfsMultihash = (await orbit.determineAddress(dbName, type, { |
const ipfsMultihash = (await orbit.determineAddress(dbName, type, { |
||||
accessController: { write: [identityId] }, |
accessController: { write: [identityId] }, |
||||
})).root; |
})).root; |
||||
return `/orbitdb/${ipfsMultihash}/${dbName}`; |
return `/orbitdb/${ipfsMultihash}/${dbName}`; |
||||
} |
} |
||||
|
|
||||
|
export default determineDBAddress; |
||||
|
@ -1,22 +1,21 @@ |
|||||
import { put, all, take } from 'redux-saga/effects' |
import { put, all, take } from 'redux-saga/effects'; |
||||
|
|
||||
import { breezeActions } from '@ezerous/breeze' |
import { breezeActions } from '@ezerous/breeze'; |
||||
import { drizzleActions } from '@ezerous/drizzle' |
import { drizzleActions } from '@ezerous/drizzle'; |
||||
|
|
||||
function * initOrbitDatabases (action) { |
function* initOrbitDatabases(action) { |
||||
const { account, breeze} = action; |
const { account, breeze } = action; |
||||
yield put(breezeActions.orbit.orbitInit(breeze, account)); //same as breeze.initOrbit(account);
|
yield put(breezeActions.orbit.orbitInit(breeze, account)); // same as breeze.initOrbit(account);
|
||||
} |
} |
||||
|
|
||||
function * orbitSaga () { |
function* orbitSaga() { |
||||
const res = yield all([ |
const res = yield all([ |
||||
take(drizzleActions.drizzle.DRIZZLE_INITIALIZED), |
take(drizzleActions.drizzle.DRIZZLE_INITIALIZED), |
||||
take(breezeActions.breeze.BREEZE_INITIALIZED), |
take(breezeActions.breeze.BREEZE_INITIALIZED), |
||||
take(drizzleActions.account.ACCOUNTS_FETCHED) |
take(drizzleActions.account.ACCOUNTS_FETCHED), |
||||
]); |
]); |
||||
|
|
||||
yield initOrbitDatabases({breeze:res[1].breeze, account: res[2].accounts[0]}); |
yield initOrbitDatabases({ breeze: res[1].breeze, account: res[2].accounts[0] }); |
||||
} |
} |
||||
|
|
||||
export default orbitSaga |
export default orbitSaga; |
||||
|
|
||||
|
Loading…
Reference in new issue