Fix bug with adding image sources quickly
This commit is contained in:
parent
5231d14937
commit
c1ee335437
@ -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 },
|
||||
}));
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user