Skip to content

Commit 0c091ca

Browse files
author
Jonatan Salas
committed
#2 Added delete functionality
1 parent 6b97492 commit 0c091ca

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/components/common/FileInfo.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component, PropTypes } from 'react';
2-
import { Col } from 'react-bootstrap';
2+
import { Col, Glyphicon } from 'react-bootstrap';
33
import filesize from 'filesize';
44

55
export default class FileUploadItem extends Component {
@@ -16,7 +16,7 @@ export default class FileUploadItem extends Component {
1616
};
1717

1818
render() {
19-
let { file, height, width } = this.props;
19+
let { file, height, width, onClick } = this.props;
2020

2121
const containerStyle = {
2222
margin: "auto",
@@ -38,6 +38,12 @@ export default class FileUploadItem extends Component {
3838
paddingRight: "10px"
3939
};
4040

41+
const glyphSizeStyle = {
42+
textAlign: 'left',
43+
paddingLeft: "10px",
44+
paddingBottom: "10px"
45+
};
46+
4147
const imgStyle = {
4248
marginTop: "10px",
4349
display: 'block',
@@ -57,9 +63,12 @@ export default class FileUploadItem extends Component {
5763
<Col xs={4} md={4}>
5864
<div style={containerStyle}>
5965
<img height={height} width={width} src={image} style={imgStyle}/>
60-
<div style={textContainerStyle}>
66+
<div style={textContainerStyle} onClick={onClick}>
6167
<p style={fileNameStyle}>{filename}</p>
62-
<p style={fileSizeStyle}>{filesize(file.size)}</p>
68+
<p style={fileSizeStyle}>
69+
<Glyphicon glyph="trash"/>
70+
{" " + filesize(file.size)}
71+
</p>
6372
</div>
6473
</div>
6574
</Col>

src/components/field/FileUpload.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class FileUpload extends Component {
1616
};
1717

1818
onDrop = (files) => {
19+
//TODO filter to avoid duplicates
1920
let fileArray = [...files, ...this.state.files];
2021

2122
this.setState({ files: fileArray });
@@ -38,6 +39,13 @@ export default class FileUpload extends Component {
3839
});
3940
};
4041

42+
deleteItem = (position) => {
43+
let { files } = this.state;
44+
files.splice(position, 1);
45+
46+
this.setState({ files: files });
47+
};
48+
4149
render() {
4250
let { files } = this.state;
4351

@@ -81,7 +89,7 @@ export default class FileUpload extends Component {
8189
<div style={rowStyle}>
8290
<Row>{
8391
files.map((file, index) => (
84-
<FileInfo key={index} file={file}/>
92+
<FileInfo key={index} file={file} onClick={() => this.deleteItem(index)}/>
8593
))
8694
}
8795
</Row>

0 commit comments

Comments
 (0)