From 05671c37715e760ec45dd0f2680d6c06a6a4873c Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 4 Apr 2019 12:49:09 -0400 Subject: [PATCH] cleanup create project --- app/components/projects/CreateProject.jsx | 9 +++------ app/components/projects/Project.jsx | 8 +++++--- app/utils/images.js | 3 +-- app/utils/ipfs.js | 5 +++++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/components/projects/CreateProject.jsx b/app/components/projects/CreateProject.jsx index 6a44bb8..f33c9a2 100644 --- a/app/components/projects/CreateProject.jsx +++ b/app/components/projects/CreateProject.jsx @@ -9,7 +9,7 @@ import Button from '@material-ui/core/Button' import InputAdornment from '@material-ui/core/InputAdornment' import CloudUpload from '@material-ui/icons/CloudUpload' import { withStyles } from '@material-ui/core/styles' -import { formatForIpfs, uploadToIpfs } from '../../utils/ipfs' +import { formatForIpfs, uploadToIpfs, formatMedia, isWeb } from '../../utils/ipfs' import { FundingContext } from '../../context' const { addProject } = LiquidPledging.methods @@ -65,10 +65,7 @@ const styles = theme => ({ } }) -const isWeb = str => str.includes('http') -const formatMedia = str => { - return isWeb(str) ? str : `/root/${str}` -} + const createJSON = values => { const { title, @@ -385,7 +382,7 @@ const SubmissionSection = ({ classes, history }) => { onBlur={handleBlur} value={values.description || ''} /> - + ) } diff --git a/app/components/projects/Project.jsx b/app/components/projects/Project.jsx index 99305e6..4b36b69 100644 --- a/app/components/projects/Project.jsx +++ b/app/components/projects/Project.jsx @@ -18,6 +18,7 @@ import { toEther } from '../../utils/conversions' import { getTokenLabel } from '../../utils/currencies' import { timeSinceBlock } from '../../utils/dates' import { getFiles } from '../../utils/ipfs' +import { getImageType } from '../../utils/images' import { useProjectData } from './hooks' const styles = theme => ({ @@ -153,8 +154,7 @@ const formatMedia = content => { return src } -const formatAvatar = content => { - const type = 'image/gif' +const formatAvatar = (content, type) => { const blob = new Blob([content], {type}) const src = URL.createObjectURL(blob) return src @@ -184,8 +184,10 @@ const getAvatarSrc = assets => { if (!assets) return null const { avatar } = getProjectManifest(assets) if (avatar.includes('http')) return avatar + const type = getImageType(avatar) return formatAvatar( - assets.find(a => a.name === getFile(avatar)).content + assets.find(a => a.name === getFile(avatar)).content, + type ) } diff --git a/app/utils/images.js b/app/utils/images.js index 1d668ef..a020fe3 100644 --- a/app/utils/images.js +++ b/app/utils/images.js @@ -6,7 +6,6 @@ const typeMap = { } export const getImageType = file => { - const { name } = file - const suffix = name.split('.').slice(-1)[0].toLowerCase() + const suffix = file.split('.').slice(-1)[0].toLowerCase() return typeMap[suffix] ? typeMap[suffix] : 'image/jpeg' } diff --git a/app/utils/ipfs.js b/app/utils/ipfs.js index 8fdbd75..7d4898f 100644 --- a/app/utils/ipfs.js +++ b/app/utils/ipfs.js @@ -79,3 +79,8 @@ export const getFiles = CID => { }) }) } + +export const isWeb = str => str.includes('http') +export const formatMedia = str => { + return isWeb(str) ? str : `/root/${str}` +}