cache warming
This commit is contained in:
@@ -1106,6 +1106,56 @@ const DetailPanel = ({
|
|||||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||||
}, [zoomedPreview, zoomDisplay]);
|
}, [zoomedPreview, zoomDisplay]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof ensureAssetUrl !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const warmNavigator = (navigator) => {
|
||||||
|
const { documentId, asset, ordinal, canGoPrev, canGoNext } = navigator;
|
||||||
|
if (!documentId || !asset || !Number.isFinite(ordinal)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const requests = [];
|
||||||
|
if (canGoPrev) {
|
||||||
|
const prevOrdinal = Math.max(1, ordinal - 1);
|
||||||
|
requests.push(
|
||||||
|
ensureAssetUrl(documentId, asset, {
|
||||||
|
start: prevOrdinal,
|
||||||
|
limit: 1,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (canGoNext) {
|
||||||
|
const nextOrdinal = ordinal + 1;
|
||||||
|
requests.push(
|
||||||
|
ensureAssetUrl(documentId, asset, {
|
||||||
|
start: nextOrdinal,
|
||||||
|
limit: 1,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
requests.forEach((promise) => promise?.catch?.(() => {}));
|
||||||
|
};
|
||||||
|
|
||||||
|
warmNavigator(singlePreviewNavigator);
|
||||||
|
warmNavigator(stackPreviewNavigator);
|
||||||
|
}, [
|
||||||
|
ensureAssetUrl,
|
||||||
|
singlePreviewNavigator.documentId,
|
||||||
|
singlePreviewNavigator.asset,
|
||||||
|
singlePreviewNavigator.ordinal,
|
||||||
|
singlePreviewNavigator.canGoPrev,
|
||||||
|
singlePreviewNavigator.canGoNext,
|
||||||
|
stackPreviewNavigator.documentId,
|
||||||
|
stackPreviewNavigator.asset,
|
||||||
|
stackPreviewNavigator.ordinal,
|
||||||
|
stackPreviewNavigator.canGoPrev,
|
||||||
|
stackPreviewNavigator.canGoNext,
|
||||||
|
]);
|
||||||
|
|
||||||
const zoomImageStyle = useMemo(() => {
|
const zoomImageStyle = useMemo(() => {
|
||||||
if (!zoomNative) {
|
if (!zoomNative) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user