diff --git a/src/app/config.d.ts b/src/app/config.d.ts index c93c4f5184..c0a1219503 100644 --- a/src/app/config.d.ts +++ b/src/app/config.d.ts @@ -26,7 +26,7 @@ export interface AppConfig { hero: Hero module: Module - custom: Custom + custom?: Custom } export interface Custom { css: string[] diff --git a/src/components/layout/header/internal/AnimatedLogo.tsx b/src/components/layout/header/internal/AnimatedLogo.tsx index 9126eb1830..c835933ac0 100644 --- a/src/components/layout/header/internal/AnimatedLogo.tsx +++ b/src/components/layout/header/internal/AnimatedLogo.tsx @@ -4,9 +4,11 @@ import { useQuery } from '@tanstack/react-query' import { useCallback } from 'react' import { AnimatePresence, m } from 'framer-motion' import { useRouter } from 'next/navigation' +import type { Bilibili } from '~/app/config' import { getAdminUrl, isLogged, useViewport } from '~/atoms' import { useSingleAndDoubleClick } from '~/hooks/common/use-single-double-click' +import { noopObj } from '~/lib/noop' import { Routes } from '~/lib/route-builder' import { toast } from '~/lib/toast' import { useAppConfigSelector } from '~/providers/root/aggregation-data-provider' @@ -23,7 +25,9 @@ const TapableLogo = () => { enabled: false, }) - const { liveId } = useAppConfigSelector((config) => config.module.bilibili)! + const { liveId } = (useAppConfigSelector( + (config) => config.module?.bilibili, + ) || noopObj) as Bilibili const goLive = useCallback(() => { window.open(`https://live.bilibili.com/${liveId}`) diff --git a/src/components/layout/header/internal/SiteOwnerAvatar.tsx b/src/components/layout/header/internal/SiteOwnerAvatar.tsx index 8f72a3f6f7..e477e08462 100644 --- a/src/components/layout/header/internal/SiteOwnerAvatar.tsx +++ b/src/components/layout/header/internal/SiteOwnerAvatar.tsx @@ -12,7 +12,9 @@ import { export const SiteOwnerAvatar: Component = ({ className }) => { const avatar = useAggregationSelector((data) => data.user.avatar) - const liveId = useAppConfigSelector((config) => config.module.bilibili.liveId) + const liveId = useAppConfigSelector( + (config) => config.module?.bilibili?.liveId, + ) const { data: isLiving } = useQuery({ queryKey: ['live-check'], diff --git a/src/components/widgets/shared/AsideDonateButton.tsx b/src/components/widgets/shared/AsideDonateButton.tsx index a554ed2413..8f968c76e8 100644 --- a/src/components/widgets/shared/AsideDonateButton.tsx +++ b/src/components/widgets/shared/AsideDonateButton.tsx @@ -20,7 +20,7 @@ const overlayShowAtom = atom(false) export const AsideDonateButton = () => { const isClient = useIsClient() - const donate = useAppConfigSelector((config) => config.module.donate)! + const donate = useAppConfigSelector((config) => config.module?.donate) const overlayOpen = useAtomValue(overlayShowAtom) diff --git a/src/providers/root/script-inject-provider.tsx b/src/providers/root/script-inject-provider.tsx index 34046cb84f..8be3a02847 100644 --- a/src/providers/root/script-inject-provider.tsx +++ b/src/providers/root/script-inject-provider.tsx @@ -5,7 +5,7 @@ import Script from 'next/script' import { useAppConfigSelector } from './aggregation-data-provider' export const ScriptInjectProvider = () => { - const scripts = useAppConfigSelector((config) => config.custom.scripts) + const scripts = useAppConfigSelector((config) => config.custom?.scripts) if (!scripts) return null return ( <>