From bbc3bbabca9fbab717b9e848ec7e7741a9881e7a Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Sat, 20 Apr 2024 14:11:01 -0400 Subject: [PATCH] Add fallback image for broken images --- src/assets/images/broken-image-fallback.png | Bin 0 -> 8399 bytes src/assets/symbols.svg | 7 +++- src/shared/components/common/pictrs-image.tsx | 36 +++++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/assets/images/broken-image-fallback.png diff --git a/src/assets/images/broken-image-fallback.png b/src/assets/images/broken-image-fallback.png new file mode 100644 index 0000000000000000000000000000000000000000..84e828fbf71b6c024de45c64a08df31f27ccd180 GIT binary patch literal 8399 zcmeHtS6Gu<*KH^&D2Np4g34BUGjt5m4FLrK={10$gkB^R>6T3|+d}V6FqDXZAT>&J z3lahbq(+E9=r#1fzu5nI&bc|)-_>`KCr{qIYpwaNtU2ZwVwZS5^3LGSR-NhZ?3&z`Rn%%2@}JnuuYTO`clMU+hFVq>XLCbVRPWP4kp5cR z5QxJCW(UZf%aL@KpF&PYGSc%xIGFx>;lKOwzsJF;<_zwaiqEfGb%CpsOAl}l5-+KL z{z5JokvbN-&WRB($t%`l_M1~dJh3v06e@bIpp?{vq~6#^OD`1Ab( zO)8Fo&9o_C`J2#Lv}q{Lwk%hU)9-u9t9z~qa63|JmrI67G6X=OFKuvzmgxehz@l)!;Yuoe`zZbZK;LaEyEAj+9w$j z;vmjHa-Ym*xNXjUA8C&?%~JBjkj}{&)2ADae0Zcs?Go^Q$i`rOW%As5Zsf}gxP)&X z9`!8rnd91;nma@2wf}@b9mnduvE~()FJUY$DfOiArf_eZ53_@|lp1n*tX?*Rw_n02 zh6*A@u{{^M8p&6ktg$Z^!ql%jDUk32;;iL}b)RVT2aB7>bqTtO@XFBj#&}FL){TDh zLv73Dr%bo7ud?%=Ke;;gQ5p<%J6rwlO-nzkMNU4_r%yc=;1Dt9$NA0nzUxZh8|-(< ze^MRY6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Oa_1^;{C|j82K%uLS8Zgy}X_IMRCy%9bo-&ZWH=R=h@T~4RT05=oTO$w&A?ZUj&pafB|L9<8 zMl%cUdeQUpfApK{a|4zn0{_)6TmuL~%!v%5@ZkbEasBTt_hCN2aAgrR`EEfI{XC5p z7nTvI&#yH`IfV-JD)onnq4Yv&vr~7{!k{5sn*TW@st*jyPv3Lqfv5E0$osekTRMsq z9Sdt*3+X3=P-XgF7fXW{=UnoH3uBIGWWnu{5N!31&EuzGoKPPkzWs5a|u1VsjJUtud$>7169H&eHg!c+*lVZQ*G=!CD zxl*As;Aj$u5m5?yz{fAS{rNak-bq^#g97`TyAaVmGYbJKWxu+t+o4M1Xq2n)reM>Szs@ zgZx#{RSpQOzyAOF3&4D_&jD88NIT`6er>pEMy}-l{c;qT zOYtZ#1wSh3$2*hCJAY){c%)0Si+p*~-Qda@58eDuh4baOcnoOGc$nUAYOg<-u8SDd zSAN1K2OO!Z@|%s|d|--_)FeX0VDrz;$+%P$-pobpbeyzL)`cPo7jRthvkZX~{ucfK zK~ZcarCRGm)w%4!pPSRGpH+XX#K3lfzIW%TCZs~%vil}4y>UOZbJfi7V!t|Bt z+dx)wtNs$AF9TZY)msgqqbm>o)$!dPD5I4!O-nb*VG54Du$^%-<;`YbEED&s zi;LRqzBYK^=hj50Tn&bGv#q%}aOjvf`nn!q%*rv~aI}nqe$q+nD=DHaoFf8G?oP&D zzn6Z$o*A~;3tgrTsFZ}D?;YayXW1%UxaG@k|7}#vEv-qG?8s|!zSPbm$(-a*a0P@l zR@eno;-_+*VY!Iu+(1u M2m`IEKOLU^53*)PTmS$7 literal 0 HcmV?d00001 diff --git a/src/assets/symbols.svg b/src/assets/symbols.svg index 87d63361..c9fda729 100644 --- a/src/assets/symbols.svg +++ b/src/assets/symbols.svg @@ -170,8 +170,11 @@ - - + + + + + diff --git a/src/shared/components/common/pictrs-image.tsx b/src/shared/components/common/pictrs-image.tsx index 9a5f450e..d942aba6 100644 --- a/src/shared/components/common/pictrs-image.tsx +++ b/src/shared/components/common/pictrs-image.tsx @@ -1,9 +1,10 @@ import classNames from "classnames"; -import { Component } from "inferno"; +import { Component, linkEvent } from "inferno"; import { UserService } from "../../services"; import { setIsoData } from "@utils/app"; import { IsoData } from "../../interfaces"; +import { getStaticDir } from "@utils/env"; const iconThumbnailSize = 96; const thumbnailSize = 256; @@ -20,13 +21,35 @@ interface PictrsImageProps { cardTop?: boolean; } -export class PictrsImage extends Component { +interface PictrsImageState { + src: string; +} + +function handleImgLoadError(i: PictrsImage) { + i.setState({ + src: `${getStaticDir()}/assets/images/broken-image-fallback.png`, + }); +} + +export class PictrsImage extends Component { private readonly isoData: IsoData = setIsoData(this.context); + state: PictrsImageState = { + src: this.props.src, + }; + + componentDidUpdate(prevProps: PictrsImageProps) { + if (prevProps.src !== this.props.src) { + this.setState({ src: this.props.src }); + } + } + render() { - const { src, icon, iconOverlay, banner, thumbnail, nsfw, pushup, cardTop } = + const { icon, iconOverlay, banner, thumbnail, nsfw, pushup, cardTop } = this.props; + const { src } = this.state; + const blurImage = nsfw && (UserService.Instance.myUserInfo?.local_user_view.local_user.blur_nsfw ?? @@ -58,6 +81,7 @@ export class PictrsImage extends Component { "avatar-pushup": pushup, "card-img-top": cardTop, })} + onError={linkEvent(this, handleImgLoadError)} /> ) @@ -70,14 +94,14 @@ export class PictrsImage extends Component { let url: URL | undefined; try { - url = new URL(this.props.src); + url = new URL(this.state.src); } catch { - return this.props.src; + return this.state.src; } // If there's no match, then it's not a pictrs image if (!url.pathname.includes("/pictrs/image/")) { - return this.props.src; + return this.state.src; } // Keeps original search params. Could probably do `url.search = ""` here.