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) {
|
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 },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user