Skip to content

Commit 3327c9e

Browse files
committed
fix: no file returns empty for file display
1 parent 3db3345 commit 3327c9e

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

src/components/display-selector.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { Typography, Avatar, Checkbox, Icon } from 'antd'
2+
import { Typography, Avatar, Checkbox } from 'antd'
33
import styled from 'styled-components/macro'
44
import PropTypes from 'prop-types'
55
import GTCRAddress from './gtcr-address'
@@ -9,6 +9,7 @@ import { ZERO_ADDRESS } from '../utils/string'
99
import RichAddress from './rich-address'
1010
import ETHAddress from './eth-address'
1111
import LongText from './long-text'
12+
import FileDisplay from './file-display'
1213

1314
const pohRichAddress = 'eip155:1:0xc5e9ddebb09cd64dfacab4011a0d5cedaf7c9bdb'
1415

@@ -37,32 +38,7 @@ const DisplaySelector = ({ type, value, linkImage, allowedFileTypes }) => {
3738
case ItemTypes.LONG_TEXT:
3839
return <LongText value={value} />
3940
case ItemTypes.FILE: {
40-
if (!value)
41-
return (
42-
<a target="_blank" rel="noopener noreferrer" href="/#">
43-
View File <Icon type="paper-clip" />
44-
</a>
45-
)
46-
47-
if (!allowedFileTypes) return 'No allowed file types specified'
48-
49-
const allowedFileTypesArr = allowedFileTypes.split(' ')
50-
if (allowedFileTypesArr.length === 0)
51-
return 'No allowed file types specified'
52-
53-
const fileExtension = value.slice(value.lastIndexOf('.') + 1)
54-
if (!allowedFileTypesArr.includes(fileExtension))
55-
return 'Forbidden file type'
56-
57-
return (
58-
<a
59-
href={`${process.env.REACT_APP_IPFS_GATEWAY}${value || ''}`}
60-
target="_blank"
61-
rel="noopener noreferrer"
62-
>
63-
View File <Icon type="paper-clip" />
64-
</a>
65-
)
41+
return <FileDisplay value={value} allowedFileTypes={allowedFileTypes} />
6642
}
6743
case ItemTypes.IMAGE:
6844
return value ? (

src/components/file-display.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Icon } from 'antd'
2+
import React from 'react'
3+
4+
const FileDisplay = ({ value, allowedFileTypes }) => {
5+
if (!value) return <span style={{ color: 'gray' }}>empty</span>
6+
7+
if (!allowedFileTypes) return 'No allowed file types specified'
8+
9+
const allowedFileTypesArr = allowedFileTypes.split(' ')
10+
if (allowedFileTypesArr.length === 0) return 'No allowed file types specified'
11+
12+
const fileExtension = value.slice(value.lastIndexOf('.') + 1)
13+
if (!allowedFileTypesArr.includes(fileExtension)) return 'Forbidden file type'
14+
15+
return (
16+
<a
17+
href={`${process.env.REACT_APP_IPFS_GATEWAY}${value || ''}`}
18+
target="_blank"
19+
rel="noopener noreferrer"
20+
>
21+
View File <Icon type="paper-clip" />
22+
</a>
23+
)
24+
}
25+
26+
export default FileDisplay

0 commit comments

Comments
 (0)