Przeglądaj źródła

update CommentEditor

jam411 3 lat temu
rodzic
commit
9c68f2e70c

+ 4 - 2
packages/app/src/components/PageComment/CommentEditor.tsx

@@ -14,7 +14,8 @@ import { IInterceptorManager } from '~/interfaces/interceptor-manager';
 import { RendererOptions } from '~/services/renderer/renderer';
 import { useSWRxPageComment } from '~/stores/comment';
 import {
-  useCurrentPagePath, useCurrentPageId, useCurrentUser, useRevisionId, useRendererConfig,
+  useCurrentPagePath, useCurrentPageId, useCurrentUser, useRevisionId, useRendererConfig, useIsSlackConfigured,
+  useEditorConfig,
 } from '~/stores/context';
 import { useSWRxSlackChannels, useIsSlackEnabled } from '~/stores/editor';
 import { useIsMobile } from '~/stores/ui';
@@ -73,6 +74,8 @@ export const CommentEditor = (props: PropsType): JSX.Element => {
   const { data: isSlackEnabled, mutate: mutateIsSlackEnabled } = useIsSlackEnabled();
   const { data: slackChannelsData } = useSWRxSlackChannels(currentPagePath);
   const { data: rendererConfig } = useRendererConfig();
+  const { data: isSlackConfigured } = useIsSlackConfigured();
+  const { data: upload } = useEditorConfig();
 
   const [isReadyToUse, setIsReadyToUse] = useState(!isForNewComment);
   const [comment, setComment] = useState(commentBody ?? '');
@@ -289,7 +292,6 @@ export const CommentEditor = (props: PropsType): JSX.Element => {
     }
     const isUploadable = rendererConfig.upload.image || rendererConfig.upload.file;
     const isUploadableFile = rendererConfig.upload.file;
-    const isSlackConfigured = rendererConfig.isSlackConfigured;
 
     return (
       <>

+ 0 - 6
packages/app/src/interfaces/services/renderer.ts

@@ -18,10 +18,4 @@ export type RendererConfig = {
 
   plantumlUri: string | null,
   blockdiagUri: string | null,
-
-  upload: {
-    image: string,
-    file: string,
-  },
-  isSlackConfigured: boolean,
 } & XssOptionConfig;

+ 9 - 14
packages/app/src/pages/[[...path]].page.tsx

@@ -59,6 +59,7 @@ import {
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
   useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig, useEditingMarkdown,
+  useEditorConfig,
 } from '../stores/context';
 import { useXss } from '../stores/xss';
 
@@ -150,7 +151,7 @@ type Props = CommonProps & {
   // highlightJsStyle: string,
   // isAllReplyShown: boolean,
   // isContainerFluid: boolean,
-  // editorConfig: any,
+  editorConfig: any,
   isEnabledStaleNotification: boolean,
   // isEnabledLinebreaks: boolean,
   // isEnabledLinebreaksInComments: boolean,
@@ -182,7 +183,7 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
 
   // commons
   useXss(new Xss());
-  // useEditorConfig(props.editorConfig);
+  useEditorConfig(props.editorConfig);
   useCsrfToken(props.csrfToken);
 
   // UserUISettings
@@ -476,12 +477,12 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
   // props.isEnabledLinebreaks = configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks');
   // props.isEnabledLinebreaksInComments = configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments');
   props.disableLinkSharing = configManager.getConfig('crowi', 'security:disableLinkSharing');
-  // props.editorConfig = {
-  //   upload: {
-  //     image: crowi.fileUploadService.getIsUploadable(),
-  //     file: crowi.fileUploadService.getFileUploadEnabled(),
-  //   },
-  // };
+  props.editorConfig = {
+    upload: {
+      image: crowi.fileUploadService.getIsUploadable(),
+      file: crowi.fileUploadService.getFileUploadEnabled(),
+    },
+  };
   // props.adminPreferredIndentSize = configManager.getConfig('markdown', 'markdown:adminPreferredIndentSize');
   // props.isIndentSizeForced = configManager.getConfig('markdown', 'markdown:isIndentSizeForced');
 
@@ -500,12 +501,6 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
-
-    upload: {
-      image: crowi.fileUploadService.getIsUploadable(),
-      file: crowi.fileUploadService.getFileUploadEnabled(),
-    },
-    isSlackConfigured: crowi.slackIntegrationService.isSlackConfigured,
   };
 
   props.sidebarConfig = {

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

@@ -24,6 +24,10 @@ export const useInterceptorManager = (): SWRResponse<InterceptorManager, Error>
   return useStaticSWR<InterceptorManager, Error>('interceptorManager', undefined, { fallbackData: new InterceptorManager() });
 };
 
+export const useEditorConfig = (initialData?: string): SWRResponse<string, Error> => {
+  return useStaticSWR<string, Error>('editorConfig', initialData);
+};
+
 export const useCsrfToken = (initialData?: string): SWRResponse<string, Error> => {
   return useStaticSWR<string, Error>('csrfToken', initialData);
 };