@@ -4,8 +4,16 @@ import React from 'react'
4
4
import useSWRImmutable from 'swr/immutable'
5
5
import fetcher from '@/lib/tabby/fetcher'
6
6
import { cn } from '@/lib/utils'
7
+ import { mutate } from 'swr'
7
8
8
9
const NOT_FOUND_ERROR = 'not_found'
10
+ let hasCustomLogo = true
11
+
12
+ export const mutateBrandingLogo = ( url : string ) => {
13
+ hasCustomLogo = true
14
+ mutate ( url )
15
+ }
16
+
9
17
interface BrandingLogoProps extends React . HTMLAttributes < HTMLImageElement > {
10
18
customLogoUrl : string
11
19
defaultLogoUrl : string
@@ -29,13 +37,15 @@ export const BrandingLogo = ({
29
37
const {
30
38
data : avatarImageSrc ,
31
39
isLoading,
40
+ error
32
41
} = useSWRImmutable ( customLogoUrl , ( url : string ) => {
33
- if ( ! customLogoUrl ) return undefined
42
+ if ( ! customLogoUrl || ! hasCustomLogo ) return undefined
34
43
35
44
return fetcher ( url , {
36
45
responseFormatter : async response => {
37
46
const blob = await response . blob ( )
38
47
const buffer = Buffer . from ( await blob . arrayBuffer ( ) )
48
+ hasCustomLogo = true
39
49
return `data:image/png;base64,${ buffer . toString ( 'base64' ) } `
40
50
} ,
41
51
errorHandler : response => {
@@ -45,6 +55,11 @@ export const BrandingLogo = ({
45
55
} )
46
56
} )
47
57
58
+ if ( error ?. message === NOT_FOUND_ERROR ) {
59
+ hasCustomLogo = false
60
+ }
61
+
62
+ // todo fix height mutate
48
63
if ( isLoading ) {
49
64
// placeholder
50
65
return < div { ...props } className = { className } />
@@ -53,10 +68,10 @@ export const BrandingLogo = ({
53
68
return < img
54
69
src = { avatarImageSrc ?? defaultLogoUrl }
55
70
alt = { alt }
56
- { ...props }
57
71
className = { cn (
58
72
className ,
59
73
avatarImageSrc ? classNames ?. customLogo : classNames ?. defaultLogo
60
74
) }
75
+ { ...props }
61
76
/>
62
77
}
0 commit comments