Skip to content

Commit 412b1ce

Browse files
authored
use object (#474)
<!--変更したい場合は、`/.github/pull_request_template.md` を修正して下さい。--> # PRの概要 <!-- 変更の目的 もしくは 関連する Issue 番号 --> <!-- 以下のように書くと Issue にリンクでき、マージ時に自動で Issue を閉じられる--> <!-- closes #1 --> ## 具体的な変更内容 <!-- ビューの変更がある場合はスクショによる比較などがあるとわかりやすい --> ## 影響範囲 <!-- この関数を変更したのでこの機能にも影響がある、など --> ## 動作要件 <!-- 動作に必要な 環境変数 / 依存関係 / DBの更新 など --> ## 補足 <!-- レビューをする際に見てほしい点、ローカル環境で試す際の注意点、など --> ## レビューリクエストを出す前にチェック! - [ ] 改めてセルフレビューしたか - [ ] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 -->
1 parent 67993bd commit 412b1ce

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

web/bun.lockb

0 Bytes
Binary file not shown.

web/components/ImageFallback.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
"use client";
2-
3-
import { useEffect, useState } from "react";
4-
52
type Props = {
63
url?: string;
74
fallback: React.ReactElement;
85
width: string;
96
height: string;
10-
alt: string;
117
};
128

139
// https://medium.com/@abhishekmicosoft/handling-img-fallback-307653b2f30
14-
export function ImageFallback({ width, height, url, fallback, alt }: Props) {
15-
const [ok, setOK] = useState<boolean>(true);
16-
useEffect(() => {
17-
url;
18-
setOK(true);
19-
}, [url]);
10+
export function ImageFallback({ width, height, url }: Props) {
2011
const URL = url?.startsWith("/")
2112
? `${process.env.NEXT_PUBLIC_API_ENDPOINT}${url}`
2213
: url;
2314

24-
return ok ? (
25-
<img
26-
src={URL}
15+
return (
16+
<object
17+
data={URL}
18+
type="image/webp"
19+
width={width} // there probably prevent style shaking
20+
height={height}
2721
style={{
2822
width,
2923
height,
3024
objectFit: "cover",
3125
borderRadius: "50%",
3226
pointerEvents: "none",
3327
}}
34-
onError={() => {
35-
console.log("failed to fetch image data of:", URL);
36-
setOK(false);
37-
}}
38-
alt={alt}
39-
/>
40-
) : (
41-
<>{fallback}</>
28+
>
29+
<img
30+
src="/avatar.svg"
31+
width={width}
32+
height={height}
33+
style={{ width, height }}
34+
alt=""
35+
/>
36+
</object>
4237
);
4338
}

web/components/human/WithFallback.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export function AvatarWithFallback({ width, height, url }: Props) {
1818
sx={{ width: `${width}`, height: `${height}`, objectFit: "cover" }}
1919
/>
2020
}
21-
alt=""
2221
/>
2322
);
2423
}

web/public/avatar.svg

Lines changed: 6 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)