add faster load time to project page

This commit is contained in:
Barry Gitarts 2019-03-07 11:42:25 -05:00 committed by Barry G
parent 3b5c1b6897
commit b03c338500
2 changed files with 18 additions and 14 deletions

View File

@ -213,14 +213,14 @@ function Project({ classes, match, profile, transfers, pledges, projectAddedEven
title="media-description"
/>}
<div className={classes.infoBox}>
<LinearProgress
{amountsPledged[0] ? <LinearProgress
classes={{
colorPrimary: classes.linearColorPrimary,
barColorPrimary: classes.linearBarColorPrimary,
}}
variant="determinate"
value={percentToGoal}
/>
/> : <LinearProgress />}
<div className={classes.infoBoxSection}>
<span className={classes.raisedAmount}>
{`${totalPledged.toLocaleString()} ${amountsPledged[0] ? amountsPledged[0][0] : ''}`}

View File

@ -1,4 +1,6 @@
import EmbarkJS from 'Embark/EmbarkJS'
import web3 from 'Embark/web3'
import LiquidPledging from 'Embark/contracts/LiquidPledging'
import { useState, useEffect, useMemo } from 'react'
import { timeSinceBlock } from '../../utils/dates'
import { getFiles } from '../../utils/ipfs'
@ -9,9 +11,10 @@ async function getProjectAge(id, events, setState){
setState(timeSinceBlock(timestamp, 'days'))
}
async function getProjectAssets(hash, setState){
console.log({hash})
const CID = hash.split('/').slice(-1)[0]
async function getProjectAssets(projectId, setState){
EmbarkJS.onReady(async (err) => {
const projectInfo = await LiquidPledging.methods.getPledgeAdmin(projectId).call()
const CID = projectInfo.url.split('/').slice(-1)[0]
getFiles(CID)
.then((files) => {
setState(files)
@ -19,6 +22,7 @@ async function getProjectAssets(hash, setState){
console.log({files}, JSON.parse(manifest.content))
})
.catch(console.log)
})
}
const getProjectManifest = assets => assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null
@ -32,8 +36,8 @@ export function useProjectData(projectId, profile, projectAddedEvents) {
}, [projectAddedEvents])
useEffect(() => {
if (profile[0]) getProjectAssets(profile[0].url, setAssets)
}, [profile])
getProjectAssets(projectId, setAssets)
}, [projectId])
const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets])