Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified web/bun.lockb
Binary file not shown.
37 changes: 16 additions & 21 deletions web/components/ImageFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
"use client";

import { useEffect, useState } from "react";

type Props = {
url?: string;
fallback: React.ReactElement;
width: string;
height: string;
alt: string;
};

// https://medium.com/@abhishekmicosoft/handling-img-fallback-307653b2f30
export function ImageFallback({ width, height, url, fallback, alt }: Props) {
const [ok, setOK] = useState<boolean>(true);
useEffect(() => {
url;
setOK(true);
}, [url]);
export function ImageFallback({ width, height, url }: Props) {
const URL = url?.startsWith("/")
? `${process.env.NEXT_PUBLIC_API_ENDPOINT}${url}`
: url;

return ok ? (
<img
src={URL}
return (
<object
data={URL}
type="image/webp"
width={width} // there probably prevent style shaking
height={height}
style={{
width,
height,
objectFit: "cover",
borderRadius: "50%",
pointerEvents: "none",
}}
onError={() => {
console.log("failed to fetch image data of:", URL);
setOK(false);
}}
alt={alt}
/>
) : (
<>{fallback}</>
>
<img
src="/avatar.svg"
width={width}
height={height}
style={{ width, height }}
alt=""
/>
</object>
);
}
1 change: 0 additions & 1 deletion web/components/human/WithFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function AvatarWithFallback({ width, height, url }: Props) {
sx={{ width: `${width}`, height: `${height}`, objectFit: "cover" }}
/>
}
alt=""
/>
);
}
6 changes: 6 additions & 0 deletions web/public/avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.