diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-01-14 16:40:02 -0500 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-01-14 16:40:02 -0500 |
commit | a37e3935e755f9a7f1a81e51d9fee696cac681c2 (patch) | |
tree | c0ca026a1984b4c30eb35320fc303511d01f4494 /extension/src/components/BMIcon.tsx | |
parent | a8da6090454a1b1b9ca1d977138430f768ec44f1 (diff) | |
download | bookmarks-home-a37e3935e755f9a7f1a81e51d9fee696cac681c2.tar.gz bookmarks-home-a37e3935e755f9a7f1a81e51d9fee696cac681c2.tar.bz2 bookmarks-home-a37e3935e755f9a7f1a81e51d9fee696cac681c2.zip |
rewrite icon system to cache better
Diffstat (limited to 'extension/src/components/BMIcon.tsx')
-rw-r--r-- | extension/src/components/BMIcon.tsx | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/extension/src/components/BMIcon.tsx b/extension/src/components/BMIcon.tsx index 5e2f9c9..8af7115 100644 --- a/extension/src/components/BMIcon.tsx +++ b/extension/src/components/BMIcon.tsx @@ -15,14 +15,18 @@ function BMIcon(props: {imgSrc?: string, bmUrl?:string}) { } function handleImageError() { - let url = new URL(props.bmUrl!); - setBgColor(hashStringToColor(url.hostname)) + if (props.bmUrl) { + let url = new URL(props.bmUrl); + setBgColor(hashStringToColor(url.hostname)) + } setIconMode("letter"); } if (!props.imgSrc) { - let url = new URL(props.bmUrl!); - bgColor = hashStringToColor(url.hostname) + if (props.bmUrl) { + let url = new URL(props.bmUrl); + bgColor = hashStringToColor(url.hostname) + } iconMode = "letter" } @@ -31,7 +35,10 @@ function BMIcon(props: {imgSrc?: string, bmUrl?:string}) { style={bgColor ? {"--icon-bg": `rgba(${bgColor[0]}, ${bgColor[1]}, ${bgColor[2]}, 0.2)`} as React.CSSProperties : undefined}> {(() => { switch (iconMode) { case "letter": { - return (<span className={"letter"}>{new URL(props.bmUrl!).hostname.charAt(0)}</span>) + return (<span className={"letter"}>{ props.bmUrl + ? new URL(props.bmUrl).hostname.charAt(0) + : '?' + }</span>) } case "small": { return (<img alt="Bookmark icon" src={props.imgSrc}/>) |