1
1
import type { FeedViewType } from "@follow/constants"
2
2
import type { ReactNode } from "react"
3
- import { useMemo } from "react"
3
+ import { useCallback , useMemo , useState } from "react"
4
4
5
5
import type { FeedSchema } from "@/src/database/schemas/types"
6
6
import { getFeedIconSource } from "@/src/lib/image"
7
7
8
8
import type { ImageProps } from "../image/Image"
9
9
import { Image } from "../image/Image"
10
+ import { FallbackIcon } from "./fallback-icon"
10
11
11
12
export type FeedIconRequiredFeed = Pick <
12
13
FeedSchema ,
@@ -39,12 +40,15 @@ export function FeedIcon({
39
40
siteUrl,
40
41
...props
41
42
} : FeedIconProps & ImageProps ) {
43
+ const [ isError , setIsError ] = useState ( false )
42
44
const src = useMemo ( ( ) => {
43
45
return getFeedIconSource ( feed , siteUrl , fallback )
44
46
} , [ fallback , feed , siteUrl ] )
45
47
46
- if ( ! src ) {
47
- return null
48
+ const handleError = useCallback ( ( ) => setIsError ( true ) , [ ] )
49
+
50
+ if ( ! src || isError ) {
51
+ return < FallbackIcon title = { feed ?. title ?? "" } size = { size } />
48
52
}
49
53
return (
50
54
< Image
@@ -55,6 +59,7 @@ export function FeedIcon({
55
59
className = "rounded"
56
60
style = { { height : size , width : size } }
57
61
source = { { uri : src } }
62
+ onError = { handleError }
58
63
{ ...props }
59
64
/>
60
65
)
0 commit comments