Yuki Takei 3 лет назад
Родитель
Сommit
06e92e9750

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

@@ -3,6 +3,8 @@ import React, { ReactNode } from 'react';
 import { useTheme } from 'next-themes';
 import { useTheme } from 'next-themes';
 import Head from 'next/head';
 import Head from 'next/head';
 
 
+import { useGrowiTheme } from '~/stores/context';
+
 import { ThemeProvider } from '../Theme/utils/ThemeProvider';
 import { ThemeProvider } from '../Theme/utils/ThemeProvider';
 
 
 type Props = {
 type Props = {
@@ -17,6 +19,7 @@ export const RawLayout = ({ children, title, className }: Props): JSX.Element =>
   if (className != null) {
   if (className != null) {
     classNames.push(className);
     classNames.push(className);
   }
   }
+  const { data: growiTheme } = useGrowiTheme();
 
 
   // get color scheme from next-themes
   // get color scheme from next-themes
   const { resolvedTheme: colorScheme } = useTheme();
   const { resolvedTheme: colorScheme } = useTheme();
@@ -28,7 +31,7 @@ export const RawLayout = ({ children, title, className }: Props): JSX.Element =>
         <meta charSet="utf-8" />
         <meta charSet="utf-8" />
         <meta name="viewport" content="initial-scale=1.0, width=device-width" />
         <meta name="viewport" content="initial-scale=1.0, width=device-width" />
       </Head>
       </Head>
-      <ThemeProvider theme="default">
+      <ThemeProvider theme={growiTheme}>
         <div className={classNames.join(' ')} data-color-scheme={colorScheme}>
         <div className={classNames.join(' ')} data-color-scheme={colorScheme}>
           {children}
           {children}
         </div>
         </div>

+ 1 - 4
packages/app/src/pages/[[...path]].page.tsx

@@ -50,7 +50,7 @@ import {
   useCurrentUser, useCurrentPagePath,
   useCurrentUser, useCurrentPagePath,
   useIsLatestRevision,
   useIsLatestRevision,
   useIsForbidden, useIsNotFound, useIsTrashPage, useIsSharedUser,
   useIsForbidden, useIsNotFound, useIsTrashPage, useIsSharedUser,
-  useAppTitle, useSiteUrl, useConfidential, useIsEnabledStaleNotification, useIsIdenticalPath,
+  useIsEnabledStaleNotification, useIsIdenticalPath,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useDisableLinkSharing,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useDisableLinkSharing,
   useHackmdUri,
   useHackmdUri,
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
@@ -141,11 +141,8 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   }
   }
 
 
   // commons
   // commons
-  useAppTitle(props.appTitle);
-  useSiteUrl(props.siteUrl);
   useXss(new Xss());
   useXss(new Xss());
   // useEditorConfig(props.editorConfig);
   // useEditorConfig(props.editorConfig);
-  useConfidential(props.confidential);
   useCsrfToken(props.csrfToken);
   useCsrfToken(props.csrfToken);
 
 
   // UserUISettings
   // UserUISettings

+ 7 - 1
packages/app/src/pages/_app.page.tsx

@@ -12,7 +12,9 @@ import '~/styles/style-next.scss';
 
 
 import * as nextI18nConfig from '../next-i18next.config';
 import * as nextI18nConfig from '../next-i18next.config';
 import { useI18nextHMR } from '../services/i18next-hmr';
 import { useI18nextHMR } from '../services/i18next-hmr';
-import { useGrowiVersion } from '../stores/context';
+import {
+  useAppTitle, useConfidential, useGrowiTheme, useGrowiVersion, useSiteUrl,
+} from '../stores/context';
 
 
 import { CommonProps } from './commons';
 import { CommonProps } from './commons';
 // import { useInterceptorManager } from '~/stores/interceptor';
 // import { useInterceptorManager } from '~/stores/interceptor';
@@ -32,6 +34,10 @@ function GrowiApp({ Component, pageProps }: GrowiAppProps): JSX.Element {
 
 
   const commonPageProps = pageProps as CommonProps;
   const commonPageProps = pageProps as CommonProps;
   // useInterceptorManager(new InterceptorManager());
   // useInterceptorManager(new InterceptorManager());
+  useAppTitle(commonPageProps.appTitle);
+  useSiteUrl(commonPageProps.siteUrl);
+  useConfidential(commonPageProps.confidential);
+  useGrowiTheme(commonPageProps.theme);
   useGrowiVersion(commonPageProps.growiVersion);
   useGrowiVersion(commonPageProps.growiVersion);
 
 
   return (
   return (

+ 4 - 1
packages/app/src/pages/commons.ts

@@ -3,6 +3,7 @@ import { GetServerSideProps, GetServerSidePropsContext } from 'next';
 import { SSRConfig, UserConfig } from 'next-i18next';
 import { SSRConfig, UserConfig } from 'next-i18next';
 
 
 import { CrowiRequest } from '~/interfaces/crowi-request';
 import { CrowiRequest } from '~/interfaces/crowi-request';
+import { GrowiThemes } from '~/interfaces/theme';
 
 
 import * as nextI18NextConfig from '../next-i18next.config';
 import * as nextI18NextConfig from '../next-i18next.config';
 
 
@@ -12,6 +13,7 @@ export type CommonProps = {
   appTitle: string,
   appTitle: string,
   siteUrl: string,
   siteUrl: string,
   confidential: string,
   confidential: string,
+  theme: GrowiThemes,
   customTitleTemplate: string,
   customTitleTemplate: string,
   csrfToken: string,
   csrfToken: string,
   growiVersion: string,
   growiVersion: string,
@@ -23,7 +25,7 @@ export const getServerSideCommonProps: GetServerSideProps<CommonProps> = async(c
   const req: CrowiRequest = context.req as CrowiRequest;
   const req: CrowiRequest = context.req as CrowiRequest;
   const { crowi } = req;
   const { crowi } = req;
   const {
   const {
-    appService, customizeService,
+    appService, configManager, customizeService,
   } = crowi;
   } = crowi;
 
 
   const url = new URL(context.resolvedUrl, 'http://example.com');
   const url = new URL(context.resolvedUrl, 'http://example.com');
@@ -35,6 +37,7 @@ export const getServerSideCommonProps: GetServerSideProps<CommonProps> = async(c
     appTitle: appService.getAppTitle(),
     appTitle: appService.getAppTitle(),
     siteUrl: appService.getSiteUrl(),
     siteUrl: appService.getSiteUrl(),
     confidential: appService.getAppConfidential() || '',
     confidential: appService.getAppConfidential() || '',
+    theme: configManager.getConfig('crowi', 'customize:theme'),
     customTitleTemplate: customizeService.customTitleTemplate,
     customTitleTemplate: customizeService.customTitleTemplate,
     csrfToken: req.csrfToken(),
     csrfToken: req.csrfToken(),
     growiVersion: crowi.version,
     growiVersion: crowi.version,

+ 5 - 0
packages/app/src/stores/context.tsx

@@ -7,6 +7,7 @@ import useSWRImmutable from 'swr/immutable';
 import { SupportedActionType } from '~/interfaces/activity';
 import { SupportedActionType } from '~/interfaces/activity';
 // import { CustomWindow } from '~/interfaces/global';
 // import { CustomWindow } from '~/interfaces/global';
 import { RendererConfig } from '~/interfaces/services/renderer';
 import { RendererConfig } from '~/interfaces/services/renderer';
+import { GrowiThemes } from '~/interfaces/theme';
 import InterceptorManager from '~/services/interceptor-manager';
 import InterceptorManager from '~/services/interceptor-manager';
 
 
 import { TargetAndAncestors } from '../interfaces/page-listing-results';
 import { TargetAndAncestors } from '../interfaces/page-listing-results';
@@ -38,6 +39,10 @@ export const useConfidential = (initialData?: string): SWRResponse<string, Error
   return useStaticSWR('confidential', initialData);
   return useStaticSWR('confidential', initialData);
 };
 };
 
 
+export const useGrowiTheme = (initialData?: GrowiThemes): SWRResponse<GrowiThemes, Error> => {
+  return useStaticSWR('theme', initialData);
+};
+
 export const useCurrentUser = (initialData?: Nullable<IUser>): SWRResponse<Nullable<IUser>, Error> => {
 export const useCurrentUser = (initialData?: Nullable<IUser>): SWRResponse<Nullable<IUser>, Error> => {
   return useStaticSWR<Nullable<IUser>, Error>('currentUser', initialData);
   return useStaticSWR<Nullable<IUser>, Error>('currentUser', initialData);
 };
 };