Просмотр исходного кода

refactor getBackgroundImageSrc

yohei0125 3 лет назад
Родитель
Сommit
98b28366c4

+ 2 - 4
packages/app/src/components/Layout/RawLayout.tsx

@@ -30,16 +30,14 @@ export const RawLayout = ({ children, title, className }: Props): JSX.Element =>
 
   const [colorScheme, setColorScheme] = useState<Themes|undefined>(undefined);
   const [backgroundImageSrc, setBackgroundImageSrc] = useState<string | undefined>(undefined);
+
   // set colorScheme in CSR
   useEffect(() => {
     setColorScheme(resolvedTheme as Themes);
   }, [resolvedTheme]);
 
+  // set background image
   useEffect(() => {
-    if (growiTheme == null || colorScheme == null) {
-      setBackgroundImageSrc(undefined);
-      return;
-    }
     const imgSrc = getBackgroundImageSrc(growiTheme, colorScheme);
     setBackgroundImageSrc(imgSrc);
   }, [growiTheme, colorScheme]);

+ 4 - 1
packages/app/src/components/Theme/utils/ThemeImageProvider.tsx

@@ -9,7 +9,10 @@ import { getBackgroundImageSrc as getIslandBackgroundImageSrc } from '../ThemeIs
 import { getBackgroundImageSrc as getSpringBackgroundImageSrc } from '../ThemeSpring';
 import { getBackgroundImageSrc as getWoodBackgroundImageSrc } from '../ThemeWood';
 
-export const getBackgroundImageSrc = (theme: GrowiThemes, colorScheme: Themes): string | undefined => {
+export const getBackgroundImageSrc = (theme: GrowiThemes | undefined, colorScheme: Themes | undefined): string | undefined => {
+  if (theme == null || colorScheme == null) {
+    return undefined;
+  }
   switch (theme) {
     case GrowiThemes.ANTARCTIC:
       return getAntarcticBackgroundImageSrc(colorScheme);