mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
fixed image preloading
This commit is contained in:
parent
42bb303394
commit
1e4081b86e
2 changed files with 6 additions and 14 deletions
|
@ -26,27 +26,19 @@ type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {}
|
||||||
const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
|
const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
|
||||||
let ref = useRef<HTMLDivElement>(null);
|
let ref = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const items = useMemo(
|
|
||||||
() =>
|
|
||||||
photoswipe.images.map(image => ({
|
|
||||||
src: getURL(image, window.innerWidth < 768 ? PRESETS[900] : PRESETS[1600]),
|
|
||||||
})),
|
|
||||||
[photoswipe.images]
|
|
||||||
);
|
|
||||||
|
|
||||||
const closeModal = useCallback(() => modalSetShown(false), [modalSetShown]);
|
const closeModal = useCallback(() => modalSetShown(false), [modalSetShown]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
new Promise(async resolve => {
|
new Promise(async resolve => {
|
||||||
const images = await Promise.all(
|
const images = await Promise.all(
|
||||||
items.map(
|
photoswipe.images.map(
|
||||||
item =>
|
image =>
|
||||||
new Promise(resolveImage => {
|
new Promise(resolveImage => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
resolveImage({
|
resolveImage({
|
||||||
src: item.src,
|
src: getURL(image, window.innerWidth < 768 ? PRESETS[900] : PRESETS[1600]),
|
||||||
h: img.naturalHeight,
|
h: img.naturalHeight,
|
||||||
w: img.naturalWidth,
|
w: img.naturalWidth,
|
||||||
});
|
});
|
||||||
|
@ -56,7 +48,7 @@ const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
|
||||||
resolveImage({});
|
resolveImage({});
|
||||||
};
|
};
|
||||||
|
|
||||||
img.src = item.src;
|
img.src = getURL(image, PRESETS[1600]);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -73,7 +65,7 @@ const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
|
||||||
ps.listen('destroy', closeModal);
|
ps.listen('destroy', closeModal);
|
||||||
ps.listen('close', closeModal);
|
ps.listen('close', closeModal);
|
||||||
});
|
});
|
||||||
}, [items, photoswipe.index]);
|
}, [photoswipe.images, photoswipe.index]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pswp" tabIndex={-1} role="dialog" aria-hidden="true" ref={ref}>
|
<div className="pswp" tabIndex={-1} role="dialog" aria-hidden="true" ref={ref}>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.bg {
|
.bg {
|
||||||
background-color: transparent;
|
background-color: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar {
|
.bar {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue