Skip to content

Commit

Permalink
allow user to check progress and submit another crawler request
Browse files Browse the repository at this point in the history
  • Loading branch information
fazo96 committed Oct 5, 2018
1 parent 528a0ca commit f70cb2a
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 176 deletions.
8 changes: 4 additions & 4 deletions src/components/Reviews/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const styles = {
class Reviews extends Component {

render() {
const { classes, reviews = [], loading, crawling = false, onLoadMoreReviews, canLoadMore, ...otherProps } = this.props
const { classes, reviews = [], loading, onLoadMoreReviews, canLoadMore, ...otherProps } = this.props
const empty = !reviews || !reviews.length

return <Grid container spacing={16} className={classes.root}>
Expand All @@ -30,17 +30,17 @@ class Reviews extends Component {
</Card>
</Grid>}

{!loading && (empty || crawling) && <Grid item xs={12}>
{!loading && empty && <Grid item xs={12}>
<Card>
<CardHeader
avatar={<ErrorIcon/>}
title='There is nothing here yet'
subheader={crawling ? 'Your reviews from other platforms are still being imported. Once done, they will be available to you on this page shortly after.' : 'No reviews to display yet'}
subheader='No reviews to display yet'
/>
</Card>
</Grid>}

{!loading && !crawling && Array.isArray(reviews) && reviews.map((review, index) => {
{!loading && Array.isArray(reviews) && reviews.map((review, index) => {
return <Grid key={index} item xs={12} >
{review.loading && <Card>
<CardHeader
Expand Down
73 changes: 73 additions & 0 deletions src/containers/CrawlerStatus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { Component } from 'react'
// components
import {
withStyles,
CardHeader,
Grid,
Card,
CardActions,
Button
} from '@material-ui/core'
// icons
import ImportIcon from '@material-ui/icons/CloudUpload'
// redux
import { connect } from 'react-redux'
import { compose } from 'recompose'
import { pollCrawlerStatus } from 'store/modules/data/crawler'
import { push } from 'react-router-redux'

const styles = {
root: {
padding: '20px'
},
}

class CrawlerStatus extends Component {

componentDidMount() {
this.props.pollCrawlerStatus()
}

goToImportPage = () => this.props.push('/import')

render() {
const { classes, loading, starting, running } = this.props
const subtitle =
loading ? 'Checking Status...'
: starting ? 'Starting import process...'
: running ? 'An import operation is in progress'
: 'No import process running for your DID'
return (<Grid container spacing={16} className={classes.root}>
<Grid item xs={12}>
<Card>
<CardHeader
avatar={<ImportIcon />}
title='Import Reviews'
subheader={subtitle}
/>
<CardActions>
<Button disabled={loading || starting || running} onClick={this.goToImportPage}>
Import Now
</Button>
</CardActions>
</Card>
</Grid>
</Grid>)
}
}

const mapStateToProps = state => ({
loading: state.data.crawler.loading,
starting: state.data.crawler.starting,
running: state.data.crawler.running,
})

const mapDispatchToProps = {
pollCrawlerStatus,
push
}

export default compose(
withStyles(styles),
connect(mapStateToProps, mapDispatchToProps)
)(CrawlerStatus)
96 changes: 96 additions & 0 deletions src/containers/ImportReviews/ImportReviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, { Component } from 'react'
// Components
import { Grid, CircularProgress } from '@material-ui/core'
import RegularCard from 'components/MaterialDashboardPro/RegularCard'
import NavPills from 'components/MaterialDashboardPro/NavPills'
import InfoArea from 'components/MaterialDashboardPro/InfoArea'
// Icons
import Person from '@material-ui/icons/Person';
import Business from '@material-ui/icons/Business';
// Form
import ImportReviewsForm from './form'
// Redux
import { connect } from 'react-redux'
import { pollCrawlerStatus } from 'store/modules/data/crawler'

class ImportReviews extends Component {

componentDidMount() {
this.props.pollCrawlerStatus()
}

render () {
const { running, starting, loading } = this.props

if (loading || starting) {
return (
<InfoArea
icon={CircularProgress}
title='Checking Status'
description='Please Wait'
/>
)
} else if (running) {
return (
<InfoArea
icon={CircularProgress}
title='In Progress'
description='An import operation is already in progress'
/>
)
} else {
return (<Grid container justify='center'>
<NavPills
color='info'
alignCenter
tabs={[
{
tabButton: 'Individuals',
tabIcon: Person,
tabContent: (
<RegularCard
cardTitle={[
<p key={0} style={{ textAlign:'center' }}>To begin, simply enter your email & password for any of the sites below on which you have an active profile.</p>,
<p key={1} style={{ textAlign:'center' }}>We extract, merge and decentrally store your reputation in a portable format so you own and control it.</p>
]}
content={<ImportReviewsForm userType='individual' />}
/>
)
},
{
tabButton: 'Businesses',
tabIcon: Business,
tabContent: (
<RegularCard
cardTitle={[
<p key={0} style={{ textAlign: 'center' }}>To begin, simply enter your email & password for any of the sites below on which you have an active profile.</p>,
<p key={1} style={{ textAlign: 'center' }}>We extract, merge and decentrally store your reputation in a portable format so you own and control it.</p>
]}
content={<ImportReviewsForm userType='business' />}
/>
)
}
]}
/>
<Grid item xs={12} sm={12} md={12}>
<p>Chlu guarantees that no information submitted from this form is ever stored on our system</p>
<p>By submitting this form you acknowledge you are entitled to invoke your <a href='https://gdpr-info.eu/recitals/no-63/'>data access rights</a> and
<a href='https://www.i-scoop.eu/gdprarticle/gdpr-article-20-right-data-portability/'> data portability rights</a> under European <a href='https://www.eugdpr.org/'>GDPR</a> legislation.
</p>
</Grid>
</Grid>)
}
}
}

const mapStateToProps = state => ({
loading: state.data.crawler.loading,
starting: state.data.crawler.starting,
running: state.data.crawler.running,
})

const mapDispatchToProps = {
pollCrawlerStatus
}

export default connect(mapStateToProps, mapDispatchToProps)(ImportReviews)
34 changes: 34 additions & 0 deletions src/containers/ImportReviews/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { Component } from 'react'
// components
import { withStyles, Button } from '@material-ui/core'
// Forms
import BusinessCrawlerForm from './businessCrawlerForm';
import IndividualsCrawlerForm from './individualsCrawlerForm';
// redux
import { reduxForm } from 'redux-form'
import { compose } from 'recompose'

const styles = {
button: {
marginLeft: 'auto'
}
}

class ImportReviewsForm extends Component {
render () {
const { classes, handleSubmit, userType, ...otherProps } = this.props
const isBusiness = userType === 'business'
const Form = isBusiness ? BusinessCrawlerForm : IndividualsCrawlerForm

return <form onSubmit={handleSubmit}>
<Form {...otherProps} />
</form>
}
}

export default compose(
withStyles(styles),
reduxForm({
form: 'import-reviews'
})
)(ImportReviewsForm)
80 changes: 52 additions & 28 deletions src/containers/ImportReviews/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
import React, { Component } from 'react'
// Components
import { LinearProgress, Grid } from '@material-ui/core'
// Forms
import BusinessCrawlerForm from './businessCrawlerForm';
import IndividualsCrawlerForm from './individualsCrawlerForm';
// redux
import { reduxForm } from 'redux-form'
import { Button, Grid, Card, CardContent, withStyles, CardActions } from '@material-ui/core'
import ImportReviews from './ImportReviews'
// Redux
import { connect } from 'react-redux'
import { compose } from 'recompose'
import { importReviews } from 'store/modules/data/crawler'

class ImportReviews extends Component {
render () {
const { handleSubmit, crawlerRunning, userType, ...otherProps } = this.props
const isBusiness = userType === 'business'
const Form = isBusiness ? BusinessCrawlerForm : IndividualsCrawlerForm
const styles = {
root: {
padding: '20px'
},
button: {
marginLeft: 'auto'
}
}

if (crawlerRunning) {
return (
<Grid container justify='center'>
<Grid item xs={12} md={12} >
<LinearProgress size={100} />
</Grid>
</Grid>
)
} else {
return <form onSubmit={handleSubmit}>
<Form {...otherProps} />
</form>
}
class ImportReviewsPage extends Component {
render() {
const { classes, importReviews, running, starting, loading } = this.props
return (<Grid container spacing={16} justify='center' className={classes.root}>
<Grid item xs={12}>
<Card>
<CardContent>
<ImportReviews showSubmitButton={true} />
</CardContent>
<CardActions>
{ !loading && !running && <Button
onClick={importReviews}
disabled={running || starting || loading}
variant='contained'
color='primary'
type='submit'
className={classes.button}
>
Start
</Button> }
</CardActions>
</Card>
</Grid>
</Grid>)
}
}

export default reduxForm({
form: 'import-reviews'
})(ImportReviews)
const mapStateToProps = state => ({
running: state.data.crawler.running,
starting: state.data.crawler.starting,
loading: state.data.crawler.loading
})

const mapDispatchToProps = {
importReviews
}

export default compose(
withStyles(styles),
connect(mapStateToProps, mapDispatchToProps)
)(ImportReviewsPage)
2 changes: 2 additions & 0 deletions src/containers/Layout/MainLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Settings from '../Settings'
import Profile from '../Profile'
import Terms from '../Terms'
import Search from '../Search'
import ImportReviews from '../ImportReviews'
import ReviewContainer from '../Review'

class MainLayout extends Component {
Expand Down Expand Up @@ -62,6 +63,7 @@ class MainLayout extends Component {
<Route path='/search/individuals' render={() => <Search type='individuals'/>} />
<Redirect from='/search' to='/search/businesses' />
{emptyWallet && <Redirect to='/'/>}
<Route path='/import' component={ImportReviews} />
<Route path='/reputation' component={Reputation} />
<Route path='/wrote' component={ReviewsIWrote} />
<Route path='/transactions' component={Transactions} />
Expand Down
15 changes: 5 additions & 10 deletions src/containers/Reputation/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import React, { Component } from 'react'

// components
import Reviews from 'components/Reviews'

import CrawlerStatus from 'containers/CrawlerStatus'
// redux
import { readMyReputation } from 'store/modules/data/reputation'
import { pollCrawlerProgress } from 'store/modules/data/crawler'
import { connect } from 'react-redux'

class Reputation extends Component {

componentDidMount() {
if (!this.props.loading) this.props.readMyReputation()
this.props.pollCrawlerProgress()
}

loadMore = () => {
if (!this.props.loading) this.props.readMyReputation(false)
}

render() {
const { reviews, loading, loadingPage, canLoadMore, crawling } = this.props
const { reviews, loading, loadingPage, canLoadMore } = this.props
return (
<div>
<CrawlerStatus />
<Reviews
loading={loading && loadingPage === 0}
reviews={reviews}
crawling={crawling}
canLoadMore={canLoadMore}
onLoadMoreReviews={this.loadMore}
/>
Expand All @@ -39,13 +36,11 @@ const mapStateToProps = state => ({
reviews: state.data.reputation.reviews,
loading: state.data.reputation.loading,
loadingPage: state.data.reputation.loadingPage,
canLoadMore: state.data.reputation.canLoadMore,
crawling: state.data.crawler.running
canLoadMore: state.data.reputation.canLoadMore
})

const mapDispatchToProps = {
readMyReputation,
pollCrawlerProgress
readMyReputation
}

export default connect(mapStateToProps, mapDispatchToProps)(Reputation)
Loading

0 comments on commit f70cb2a

Please sign in to comment.