Skip to content

Commit b757ff9

Browse files
committed
refetch branding logo
1 parent 22fb5da commit b757ff9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

ee/tabby-ui/app/(dashboard)/settings/general/components/branding-form.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useMutation } from '@/lib/tabby/gql'
88
import { cn } from '@/lib/utils'
99
import { Button } from '@/components/ui/button'
1010
import { IconCloudUpload, IconSpinner } from '@/components/ui/icons'
11+
import { mutateBrandingLogo } from '@/components/branding-logo'
1112

1213
const updateBrandingSettingMutation = graphql(/* GraphQL */ `
1314
mutation UpdateBrandingForGeneralSettings($input: BrandingSettingInput!) {
@@ -85,9 +86,7 @@ export const BrandingForm = () => {
8586
})
8687
if (response?.data?.updateBrandingSetting) {
8788
toast.success('Successfully updated branding logo!')
88-
// todo refresh logo
89-
// await delay(500)
90-
// window.location.reload()
89+
mutateBrandingLogo('/branding/logo')
9190
} else {
9291
// Handle case where mutation fails but doesn't throw an error
9392
setIsSubmitting(false)

ee/tabby-ui/components/branding-logo.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import React from 'react'
44
import useSWRImmutable from 'swr/immutable'
55
import fetcher from '@/lib/tabby/fetcher'
66
import { cn } from '@/lib/utils'
7+
import { mutate } from 'swr'
78

89
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+
917
interface BrandingLogoProps extends React.HTMLAttributes<HTMLImageElement> {
1018
customLogoUrl: string
1119
defaultLogoUrl: string
@@ -29,13 +37,15 @@ export const BrandingLogo = ({
2937
const {
3038
data: avatarImageSrc,
3139
isLoading,
40+
error
3241
} = useSWRImmutable(customLogoUrl, (url: string) => {
33-
if (!customLogoUrl) return undefined
42+
if (!customLogoUrl || !hasCustomLogo) return undefined
3443

3544
return fetcher(url, {
3645
responseFormatter: async response => {
3746
const blob = await response.blob()
3847
const buffer = Buffer.from(await blob.arrayBuffer())
48+
hasCustomLogo = true
3949
return `data:image/png;base64,${buffer.toString('base64')}`
4050
},
4151
errorHandler: response => {
@@ -45,6 +55,11 @@ export const BrandingLogo = ({
4555
})
4656
})
4757

58+
if (error?.message === NOT_FOUND_ERROR) {
59+
hasCustomLogo = false
60+
}
61+
62+
// todo fix height mutate
4863
if (isLoading) {
4964
// placeholder
5065
return <div {...props} className={className} />
@@ -53,10 +68,10 @@ export const BrandingLogo = ({
5368
return <img
5469
src={avatarImageSrc ?? defaultLogoUrl}
5570
alt={alt}
56-
{...props}
5771
className={cn(
5872
className,
5973
avatarImageSrc ? classNames?.customLogo : classNames?.defaultLogo
6074
)}
75+
{...props}
6176
/>
6277
}

0 commit comments

Comments
 (0)