mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-14 01:48:50 +01:00
Better image fallbacks
This commit is contained in:
parent
7e2723db4e
commit
8f7c6a159b
1 changed files with 26 additions and 3 deletions
|
@ -17,13 +17,24 @@ audio = Audio track
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) {
|
function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) {
|
||||||
const { blurhash, description, meta, previewUrl, remoteUrl, url, type } =
|
const {
|
||||||
media;
|
blurhash,
|
||||||
|
description,
|
||||||
|
meta,
|
||||||
|
previewRemoteUrl,
|
||||||
|
previewUrl,
|
||||||
|
remoteUrl,
|
||||||
|
url,
|
||||||
|
type,
|
||||||
|
} = media;
|
||||||
const { original = {}, small, focus } = meta || {};
|
const { original = {}, small, focus } = meta || {};
|
||||||
|
|
||||||
const width = showOriginal ? original?.width : small?.width;
|
const width = showOriginal ? original?.width : small?.width;
|
||||||
const height = showOriginal ? original?.height : small?.height;
|
const height = showOriginal ? original?.height : small?.height;
|
||||||
const mediaURL = showOriginal ? url : previewUrl;
|
const mediaURL = showOriginal ? url : previewUrl || url;
|
||||||
|
const remoteMediaURL = showOriginal
|
||||||
|
? remoteUrl
|
||||||
|
: previewRemoteUrl || remoteUrl;
|
||||||
const orientation = width >= height ? 'landscape' : 'portrait';
|
const orientation = width >= height ? 'landscape' : 'portrait';
|
||||||
|
|
||||||
const rgbAverageColor = blurhash ? getBlurHashAverageColor(blurhash) : null;
|
const rgbAverageColor = blurhash ? getBlurHashAverageColor(blurhash) : null;
|
||||||
|
@ -113,6 +124,12 @@ function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) {
|
||||||
e.target.closest('.media-zoom').style.display = '';
|
e.target.closest('.media-zoom').style.display = '';
|
||||||
setPinchZoomEnabled(true);
|
setPinchZoomEnabled(true);
|
||||||
}}
|
}}
|
||||||
|
onError={(e) => {
|
||||||
|
const { src } = e.target;
|
||||||
|
if (src === mediaURL) {
|
||||||
|
e.target.src = remoteMediaURL;
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</QuickPinchZoom>
|
</QuickPinchZoom>
|
||||||
) : (
|
) : (
|
||||||
|
@ -131,6 +148,12 @@ function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) {
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.target.closest('.media-image').style.backgroundImage = '';
|
e.target.closest('.media-image').style.backgroundImage = '';
|
||||||
}}
|
}}
|
||||||
|
onError={(e) => {
|
||||||
|
const { src } = e.target;
|
||||||
|
if (src === mediaURL) {
|
||||||
|
e.target.src = remoteMediaURL;
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Parent>
|
</Parent>
|
||||||
|
|
Loading…
Reference in a new issue