fix updateURL calls by using id instead of index and log error
This commit is contained in:
parent
8bac8d17e9
commit
aef91fe411
|
@ -26,6 +26,7 @@ import EmptyScreen from './EmptyScreen';
|
||||||
import { AppContext } from 'pages/_app';
|
import { AppContext } from 'pages/_app';
|
||||||
import { DeduplicateContext } from 'pages/deduplicate';
|
import { DeduplicateContext } from 'pages/deduplicate';
|
||||||
import { IsArchived } from 'utils/magicMetadata';
|
import { IsArchived } from 'utils/magicMetadata';
|
||||||
|
import { logError } from 'utils/sentry';
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -250,10 +251,14 @@ const PhotoFrame = ({
|
||||||
}
|
}
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
const updateURL = (index: number) => (url: string) => {
|
const updateURL = (id: number) => (url: string) => {
|
||||||
const updateFile = (file: EnteFile) => {
|
const updateFile = (file: EnteFile) => {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
logError(
|
||||||
|
Error('file not found'),
|
||||||
|
'update called for null/undefined file '
|
||||||
|
);
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
file = {
|
file = {
|
||||||
...file,
|
...file,
|
||||||
|
@ -291,18 +296,24 @@ const PhotoFrame = ({
|
||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
setFiles((files) => {
|
setFiles((files) => {
|
||||||
|
const index = files.findIndex((file) => file.id === id);
|
||||||
files[index] = updateFile(files[index]);
|
files[index] = updateFile(files[index]);
|
||||||
return files;
|
return files;
|
||||||
});
|
});
|
||||||
|
const index = files.findIndex((file) => file.id === id);
|
||||||
return updateFile(files[index]);
|
return updateFile(files[index]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSrcURL = async (index: number, srcURL: SourceURL) => {
|
const updateSrcURL = async (id: number, srcURL: SourceURL) => {
|
||||||
const { videoURL, imageURL } = srcURL;
|
const { videoURL, imageURL } = srcURL;
|
||||||
const isPlayable = videoURL && (await isPlaybackPossible(videoURL));
|
const isPlayable = videoURL && (await isPlaybackPossible(videoURL));
|
||||||
const updateFile = (file: EnteFile) => {
|
const updateFile = (file: EnteFile) => {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
logError(
|
||||||
|
Error('file not found'),
|
||||||
|
'update called for null/undefined file '
|
||||||
|
);
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
file = {
|
file = {
|
||||||
...file,
|
...file,
|
||||||
|
@ -356,10 +367,12 @@ const PhotoFrame = ({
|
||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
setFiles((files) => {
|
setFiles((files) => {
|
||||||
|
const index = files.findIndex((file) => file.id === id);
|
||||||
files[index] = updateFile(files[index]);
|
files[index] = updateFile(files[index]);
|
||||||
return files;
|
return files;
|
||||||
});
|
});
|
||||||
setIsSourceLoaded(true);
|
setIsSourceLoaded(true);
|
||||||
|
const index = files.findIndex((file) => file.id === id);
|
||||||
return updateFile(files[index]);
|
return updateFile(files[index]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -430,7 +443,7 @@ const PhotoFrame = ({
|
||||||
selected[files[index].id] ?? false
|
selected[files[index].id] ?? false
|
||||||
}`}
|
}`}
|
||||||
file={files[index]}
|
file={files[index]}
|
||||||
updateURL={updateURL(files[index].dataIndex)}
|
updateURL={updateURL(files[index].id)}
|
||||||
onClick={onThumbnailClick(index)}
|
onClick={onThumbnailClick(index)}
|
||||||
selectable={!isSharedCollection}
|
selectable={!isSharedCollection}
|
||||||
onSelect={handleSelect(files[index].id, index)}
|
onSelect={handleSelect(files[index].id, index)}
|
||||||
|
@ -476,7 +489,7 @@ const PhotoFrame = ({
|
||||||
}
|
}
|
||||||
galleryContext.thumbs.set(item.id, url);
|
galleryContext.thumbs.set(item.id, url);
|
||||||
}
|
}
|
||||||
const newFile = updateURL(item.dataIndex)(url);
|
const newFile = updateURL(item.id)(url);
|
||||||
item.msrc = newFile.msrc;
|
item.msrc = newFile.msrc;
|
||||||
item.html = newFile.html;
|
item.html = newFile.html;
|
||||||
item.src = newFile.src;
|
item.src = newFile.src;
|
||||||
|
@ -493,9 +506,9 @@ const PhotoFrame = ({
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!fetching[item.dataIndex]) {
|
if (!fetching[item.id]) {
|
||||||
try {
|
try {
|
||||||
fetching[item.dataIndex] = true;
|
fetching[item.id] = true;
|
||||||
let urls: string[];
|
let urls: string[];
|
||||||
if (galleryContext.files.has(item.id)) {
|
if (galleryContext.files.has(item.id)) {
|
||||||
const mergedURL = galleryContext.files.get(item.id);
|
const mergedURL = galleryContext.files.get(item.id);
|
||||||
|
@ -528,7 +541,7 @@ const PhotoFrame = ({
|
||||||
[imageURL] = urls;
|
[imageURL] = urls;
|
||||||
}
|
}
|
||||||
setIsSourceLoaded(false);
|
setIsSourceLoaded(false);
|
||||||
const newFile = await updateSrcURL(item.dataIndex, {
|
const newFile = await updateSrcURL(item.id, {
|
||||||
imageURL,
|
imageURL,
|
||||||
videoURL,
|
videoURL,
|
||||||
});
|
});
|
||||||
|
@ -546,7 +559,7 @@ const PhotoFrame = ({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// no-op
|
// no-op
|
||||||
} finally {
|
} finally {
|
||||||
fetching[item.dataIndex] = false;
|
fetching[item.id] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue