Skip to content

Commit

Permalink
Canceling an file upload no longer removes the previous file
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskilinc committed Aug 9, 2021
1 parent 0691657 commit b2992e8
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ class App extends React.Component {
onFileChange(e) {
e.preventDefault();
let file = e.target.files[0];

if (file && file.type.includes("image")) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
this.setState({
file: file,
imagePreviewUrl: reader.result
});

document.querySelector("#img-preview").addEventListener("load", (e) => {
const img = e.target;
const colorThief = new ColorThief();

const color = colorThief.getColor(img);
const colors = colorThief.getPalette(img);
const dominant = `#${rgbHex(color[0], color[1], color[2])}`;
const palette = colors.map((color) => `#${rgbHex(color[0], color[1], color[2])}`);

if (file) {
if (file.type.includes("image")) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
this.setState({
dominant: dominant,
palette: palette,
displayInfoText: true,
wrongFileFormat: false
})
});
file: file,
imagePreviewUrl: reader.result
});

document.querySelector("#img-preview").addEventListener("load", (e) => {
const img = e.target;
const colorThief = new ColorThief();
const color = colorThief.getColor(img);
const colors = colorThief.getPalette(img);
const dominant = `#${rgbHex(color[0], color[1], color[2])}`;
const palette = colors.map((color) => `#${rgbHex(color[0], color[1], color[2])}`);

this.setState({
dominant: dominant,
palette: palette,
displayInfoText: true,
wrongFileFormat: false
})
});
}
} else {
this.setState({ wrongFileFormat: true, file: '', imagePreviewUrl: '', dominantColor: '', displayInfoText: false, palette: null, dominant: null })
}
} else {
this.setState({ wrongFileFormat: true, file: '', imagePreviewUrl: '', dominantColor: '', displayInfoText: false, palette: null, dominant: null })
}
}

Expand Down

0 comments on commit b2992e8

Please sign in to comment.