From 324c156ea140daa44f419bf8e2a0d75861936d3d Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 18 Feb 2025 13:43:23 +0530 Subject: [PATCH] Use last best instead of thumbnail --- .../gallery/components/viewer/data-source.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts index 4d05dcb990..058e015e5e 100644 --- a/web/packages/gallery/components/viewer/data-source.ts +++ b/web/packages/gallery/components/viewer/data-source.ts @@ -181,13 +181,20 @@ const enqueueUpdates = async (file: EnteFile) => { _state.needsRefreshByFileID.get(file.id)?.(); }; - let thumbnailData: ItemData; + // Use the last best available data, but stop showing the loading indicator + // and instead show the error indicator. + const updateFailureReason = (failureReason: ItemData["failureReason"]) => { + const lastData = _state.itemDataByFileID.get(file.id) ?? {}; + delete lastData.isContentLoading; + update({ ...lastData, failureReason }); + }; + try { const thumbnailURL = await downloadManager.renderableThumbnailURL(file); // While the types don't reflect it, it is safe to use the ! (null // assertion) here since renderableThumbnailURL can throw but will not // return undefined by default. - thumbnailData = await withDimensions(thumbnailURL!); + const thumbnailData = await withDimensions(thumbnailURL!); update({ ...thumbnailData, isContentLoading: true, @@ -201,7 +208,7 @@ const enqueueUpdates = async (file: EnteFile) => { // Notify the user of the error. The entire process will be retried when // they reopen the slide later. log.error("Failed to show thumbnail", e); - update({ failureReason: "other" }); + updateFailureReason("other"); return; } @@ -240,7 +247,7 @@ const enqueueUpdates = async (file: EnteFile) => { } } catch (e) { log.error("Failed to show file", e); - update({ ...thumbnailData, failureReason: "other" }); + updateFailureReason("other"); } };