| 1 |
import { getSiteLogo } from '@launch/api/DataApi'; |
| 2 |
import { useSiteProfile } from '@launch/hooks/useSiteProfile'; |
| 3 |
import { resizeImage } from '@shared/utils/resize-image'; |
| 4 |
import useSWRImmutable from 'swr/immutable'; |
| 5 |
|
| 6 |
export const useSiteLogo = () => { |
| 7 |
const { siteProfile, loading: profileLoading } = useSiteProfile(); |
| 8 |
|
| 9 |
const { data, error } = useSWRImmutable( |
| 10 |
profileLoading || !siteProfile |
| 11 |
? null |
| 12 |
: { |
| 13 |
key: 'site-logo', |
| 14 |
logoObjectName: siteProfile?.logoObjectName, |
| 15 |
}, |
| 16 |
async ({ logoObjectName }) => { |
| 17 |
const rawLogoUrl = await getSiteLogo(logoObjectName); |
| 18 |
return await resizeImage(rawLogoUrl, { |
| 19 |
size: { width: 256, height: 256 }, |
| 20 |
mimeType: 'image/webp', |
| 21 |
}); |
| 22 |
}, |
| 23 |
); |
| 24 |
|
| 25 |
return { |
| 26 |
logoUrl: data, |
| 27 |
error, |
| 28 |
loading: profileLoading || (!data && !error), |
| 29 |
}; |
| 30 |
}; |
| 31 |
|