Fix bug with adding image sources quickly

This commit is contained in:
Mitchell McCaffrey 2021-03-12 17:46:20 +11:00
parent 5231d14937
commit c1ee335437

View File

@ -85,11 +85,24 @@ export function useImageSource(data, defaultSources, unknownSource, thumbnail) {
function addImageSource(file) {
if (file) {
setImageSources((prevSources) => {
if (id in prevSources) {
// Check if the image source is already added
return {
...prevSources,
[id]: {
...prevSources[id],
references: prevSources[id].references + 1,
},
};
} else {
const url = URL.createObjectURL(new Blob([file]));
setImageSources((prevSources) => ({
return {
...prevSources,
[id]: { url, id, references: 1 },
}));
};
}
});
}
}