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) { function addImageSource(file) {
if (file) { if (file) {
const url = URL.createObjectURL(new Blob([file])); setImageSources((prevSources) => {
setImageSources((prevSources) => ({ if (id in prevSources) {
...prevSources, // Check if the image source is already added
[id]: { url, id, references: 1 }, return {
})); ...prevSources,
[id]: {
...prevSources[id],
references: prevSources[id].references + 1,
},
};
} else {
const url = URL.createObjectURL(new Blob([file]));
return {
...prevSources,
[id]: { url, id, references: 1 },
};
}
});
} }
} }