loading handling for projects page

This commit is contained in:
Barry Gitarts 2019-02-14 14:02:00 -05:00 committed by Barry G
parent c5b734b175
commit ad991066d7
7 changed files with 101 additions and 69 deletions

View File

@ -6,7 +6,6 @@ import { getProfilesById } from './profiles'
const createPledge = (pledge, data, profiles) => { const createPledge = (pledge, data, profiles) => {
const { id, owner, amount, blockNumber, token, commitTime, nDelegates, pledgeState, intendedProject } = data const { id, owner, amount, blockNumber, token, commitTime, nDelegates, pledgeState, intendedProject } = data
console.log({data})
const profile = profiles.find(p => p.idProfile == owner) const profile = profiles.find(p => p.idProfile == owner)
pledge.pledgeId = Number(id) pledge.pledgeId = Number(id)
pledge.owner = Number(owner) pledge.owner = Number(owner)

View File

@ -1,10 +1,9 @@
import React, { Fragment, Component } from 'react' import React, { Component } from 'react'
import MaterialTable from 'material-table' import MaterialTable from 'material-table'
import withObservables from '@nozbe/with-observables' import withObservables from '@nozbe/with-observables'
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider' import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
import { toEther } from '../utils/conversions' import { toEther } from '../utils/conversions'
import { getTokenLabel } from '../utils/currencies' import { getTokenLabel } from '../utils/currencies'
import TransferDialog from './TransferDialog'
import TransferCard from './table/TransferCard' import TransferCard from './table/TransferCard'
import WithdrawCard from './table/WithdrawCard' import WithdrawCard from './table/WithdrawCard'

View File

@ -0,0 +1,21 @@
.Loading-container {
display: flex;
flex-direction: column;
align-items: center;
}
.Loading-logo {
animation: Loading-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
margin-bottom: 20%;
}
@keyframes Loading-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@ -0,0 +1,15 @@
import React from 'react'
import Typography from '@material-ui/core/Typography'
import './Loading.css'
function Loading() {
return (
<div className="Loading-container">
<img className="Loading-logo" id="loading" src="https://our.status.im/content/images/2018/07/status_logo_blue_1--2-.png" />
<Typography style={{ fontSize: '1.5rem' }}>Hold on while we gather the latest information</Typography>
</div>
)
}
export default Loading

View File

@ -5,13 +5,9 @@ import Button from '@material-ui/core/Button'
import withObservables from '@nozbe/with-observables' import withObservables from '@nozbe/with-observables'
import { Q } from '@nozbe/watermelondb' import { Q } from '@nozbe/watermelondb'
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider' import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
import Card from '@material-ui/core/Card'
import CardHeader from '@material-ui/core/CardHeader'
import CardMedia from '@material-ui/core/CardMedia' import CardMedia from '@material-ui/core/CardMedia'
import CardContent from '@material-ui/core/CardContent'
import CardActions from '@material-ui/core/CardActions'
import CardActionArea from '@material-ui/core/CardActionArea'
import LinearProgress from '@material-ui/core/LinearProgress' import LinearProgress from '@material-ui/core/LinearProgress'
import Loading from '../base/Loading'
import Avatar from '@material-ui/core/Avatar' import Avatar from '@material-ui/core/Avatar'
import ReactPlayer from 'react-player' import ReactPlayer from 'react-player'
import { uniqBy, length } from 'ramda' import { uniqBy, length } from 'ramda'
@ -135,12 +131,12 @@ async function getProjectAssets(hash, setState){
console.log({hash}) console.log({hash})
const CID = hash.split('/').slice(-1)[0] const CID = hash.split('/').slice(-1)[0]
getFiles(CID) getFiles(CID)
.then((files) => { .then((files) => {
setState(files) setState(files)
const manifest = files[2] const manifest = files[2]
console.log({files}, JSON.parse(manifest.content)) console.log({files}, JSON.parse(manifest.content))
}) })
.catch(console.log) .catch(console.log)
} }
const getProjectManifest = assets => assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null const getProjectManifest = assets => assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null
@ -169,6 +165,7 @@ const getMediaSrc = assets => {
} }
} }
function Project({ classes, match, profile, transfers, pledges, projectAddedEvents }) { function Project({ classes, match, profile, transfers, pledges, projectAddedEvents }) {
const projectId = match.params.id const projectId = match.params.id
const [projectAge, setAge] = useState(null) const [projectAge, setAge] = useState(null)
@ -179,11 +176,9 @@ function Project({ classes, match, profile, transfers, pledges, projectAddedEven
}, [projectAge]) }, [projectAge])
useEffect(() => { useEffect(() => {
getProjectAssets(profile[0].url, setAssets) if (profile[0]) getProjectAssets(profile[0].url, setAssets)
}, [profile]) }, [profile])
const received = useMemo(() => getReceivedAmount(projectId, transfers), [projectId, transfers])
const withdrawn = useMemo(() => getWithdrawnAmount(projectId, transfers), [projectId, transfers])
const amountsPledged = useMemo(() => getAmountsPledged(pledges), [pledges]) const amountsPledged = useMemo(() => getAmountsPledged(pledges), [pledges])
const numberOfBackers = useMemo(() => getNumberOfBackers(pledges), [pledges]) const numberOfBackers = useMemo(() => getNumberOfBackers(pledges), [pledges])
const mediaType = useMemo(() => getMediaType(projectAssets), [projectAssets]) const mediaType = useMemo(() => getMediaType(projectAssets), [projectAssets])
@ -193,59 +188,62 @@ function Project({ classes, match, profile, transfers, pledges, projectAddedEven
const percentToGoal = manifest ? Math.min( const percentToGoal = manifest ? Math.min(
(Number(totalPledged) / Number(manifest.goal)) * 100, (Number(totalPledged) / Number(manifest.goal)) * 100,
100 100
) : 0 ) : 0
console.log({profile, projectAssets, mediaUrl, mediaType, amountsPledged}) console.log({profile, projectAssets, mediaUrl, mediaType, amountsPledged, pledges, transfers})
return ( return (
<div className={classes.root}> !profile.length || !projectAssets
<div className={classes.creator}> ? <Loading />
<Avatar src={manifest && manifest.avatar} /> :
<Typography className={classes.creatorName}>{manifest && `By ${manifest.creator}`}</Typography> <div className={classes.root}>
</div> <div className={classes.creator}>
<div> <Avatar src={manifest && manifest.avatar} />
<Typography className={classes.title} component="h2" gutterBottom> <Typography className={classes.creatorName}>{manifest && `By ${manifest.creator}`}</Typography>
{manifest && manifest.title} </div>
</Typography> <div>
<Typography className={classes.subTitle} component="h5" gutterBottom> <Typography className={classes.title} component="h2" gutterBottom>
{manifest && manifest.subtitle} {manifest && manifest.title}
</Typography> </Typography>
</div> <Typography className={classes.subTitle} component="h5" gutterBottom>
<div className={classes.secondRow}> {manifest && manifest.subtitle}
{mediaType </Typography>
? <ReactPlayer width="100%" height="100%" url={mediaUrl} playing={manifest.media.isPlaying} /> </div>
: <CardMedia <div className={classes.secondRow}>
component="img" {mediaType
alt="video" ? <ReactPlayer width="100%" height="100%" url={mediaUrl} playing={manifest.media.isPlaying} />
className={classes.media} : <CardMedia
src={mediaUrl} component="img"
title="media-description" alt="video"
/>} className={classes.media}
<div className={classes.infoBox}> src={mediaUrl}
<LinearProgress title="media-description"
classes={{ />}
colorPrimary: classes.linearColorPrimary, <div className={classes.infoBox}>
barColorPrimary: classes.linearBarColorPrimary, <LinearProgress
}} classes={{
variant="determinate" colorPrimary: classes.linearColorPrimary,
value={percentToGoal} barColorPrimary: classes.linearBarColorPrimary,
/> }}
<div className={classes.infoBoxSection}> variant="determinate"
<span className={classes.raisedAmount}> value={percentToGoal}
{`${totalPledged.toLocaleString()} ${amountsPledged[0] ? amountsPledged[0][0] : ''}`} />
</span> <div className={classes.infoBoxSection}>
<span className={classes.subtext}>{manifest && `pledged of ${Number(manifest.goal).toLocaleString()} goal`}</span> <span className={classes.raisedAmount}>
{`${totalPledged.toLocaleString()} ${amountsPledged[0] ? amountsPledged[0][0] : ''}`}
</span>
<span className={classes.subtext}>{manifest && `pledged of ${Number(manifest.goal).toLocaleString()} goal`}</span>
</div>
<div className={classes.infoBoxSection}>
<span className={classes.infoText}>{numberOfBackers}</span>
<span className={classes.subtext}>backers</span>
</div>
<div className={classes.infoBoxSection}>
<span className={classes.infoText}>{projectAge}</span>
<span className={classes.subtext}>days active</span>
</div>
<Button color="primary" variant="contained" style={{ height: '50px' }}>Back this project</Button>
</div> </div>
<div className={classes.infoBoxSection}>
<span className={classes.infoText}>{numberOfBackers}</span>
<span className={classes.subtext}>backers</span>
</div>
<div className={classes.infoBoxSection}>
<span className={classes.infoText}>{projectAge}</span>
<span className={classes.subtext}>days active</span>
</div>
<Button color="primary" variant="contained" style={{ height: '50px' }}>Back this project</Button>
</div> </div>
</div> </div>
</div>
) )
} }

View File

@ -119,7 +119,7 @@ function TransferCard({ row, handleClose, classes }) {
<Button size="large" onClick={close}> <Button size="large" onClick={close}>
Cancel Cancel
</Button> </Button>
<Button size="large" onClick={submitForm} color="primary" type="submit"> <Button size="large" color="primary" type="submit">
Transfer Transfer
</Button> </Button>
</CardActions> </CardActions>

View File

@ -37,7 +37,7 @@ function Withdraw({ handleClose, classes, rowData, authorizedPayment }) {
const toSend = sendFn(...args) const toSend = sendFn(...args)
const estimateGas = await toSend.estimateGas() const estimateGas = await toSend.estimateGas()
toSend toSend
.send({ gas: estimateGas + 1000 }) .send({ gas: estimateGas })
.then(res => { .then(res => {
console.log({res}) console.log({res})
}) })
@ -68,7 +68,7 @@ function Withdraw({ handleClose, classes, rowData, authorizedPayment }) {
<Card className={classes.card} elevation={0}> <Card className={classes.card} elevation={0}>
<CardContent> <CardContent>
<Typography variant="h6" component="h2"> <Typography variant="h6" component="h2">
{`${isPaying ? 'Confirm' : ''} Withdraw${isPaying ? 'al' : ''} ${values.amount || ''} ${values.amount ? getTokenLabel(rowData[6]) : ''} from Pledge ${rowData.pledgeId}`} {`${isPaying ? 'Confirm' : ''} Withdraw${isPaying ? 'al' : ''} ${values.amount || ''} ${values.amount ? getTokenLabel(rowData.pledge.token) : ''} from Pledge ${rowData.pledgeId}`}
</Typography> </Typography>
{!isPaying && <TextField {!isPaying && <TextField
className={classes.amount} className={classes.amount}