Skip to content

Commit

Permalink
feat: fallback community icon on error (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Dec 7, 2024
1 parent 1cd3e61 commit 3b7b54b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/features/labels/img/ItemIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Community, Person } from "lemmy-js-client";
import { useState } from "react";

import FakeIcon from "#/features/shared/FakeIcon";
import { cx } from "#/helpers/css";
Expand All @@ -19,6 +20,8 @@ export default function ItemIcon({
className,
slot,
}: ItemIconProps) {
const [failed, setFailed] = useState(false);

size = size ?? 28;

if (typeof item === "string")
Expand All @@ -28,13 +31,16 @@ export default function ItemIcon({

const icon = "posting_restricted_to_mods" in item ? item.icon : item.avatar;

if (icon)
if (icon && !failed)
return (
<img
style={{ width: `${size}px`, height: `${size}px` }}
src={getImageSrc(icon, {
size,
})}
onError={() => {
setFailed(true);
}}
className={cx(styles.subImgIcon, className)}
slot={slot}
/>
Expand Down

0 comments on commit 3b7b54b

Please sign in to comment.