Browse Source

update CommentEditor

jam411 3 years ago
parent
commit
a30397e9e5
1 changed files with 12 additions and 25 deletions
  1. 12 25
      packages/app/src/components/PageComment/CommentEditor.tsx

+ 12 - 25
packages/app/src/components/PageComment/CommentEditor.tsx

@@ -4,21 +4,17 @@ import React, {
 
 
 import { UserPicture } from '@growi/ui';
 import { UserPicture } from '@growi/ui';
 import {
 import {
-  Button,
-  TabContent, TabPane,
+  Button, TabContent, TabPane,
 } from 'reactstrap';
 } from 'reactstrap';
 import * as toastr from 'toastr';
 import * as toastr from 'toastr';
 
 
-import AppContainer from '~/client/services/AppContainer';
-import EditorContainer from '~/client/services/EditorContainer';
-import PageContainer from '~/client/services/PageContainer';
 import { apiPostForm } from '~/client/util/apiv1-client';
 import { apiPostForm } from '~/client/util/apiv1-client';
 import { CustomWindow } from '~/interfaces/global';
 import { CustomWindow } from '~/interfaces/global';
 import { IInterceptorManager } from '~/interfaces/interceptor-manager';
 import { IInterceptorManager } from '~/interfaces/interceptor-manager';
 import { RendererOptions } from '~/services/renderer/renderer';
 import { RendererOptions } from '~/services/renderer/renderer';
 import { useSWRxPageComment } from '~/stores/comment';
 import { useSWRxPageComment } from '~/stores/comment';
 import {
 import {
-  useCurrentPagePath, useCurrentPageId, useCurrentUser, useRevisionId,
+  useCurrentPagePath, useCurrentPageId, useCurrentUser, useRevisionId, useRendererConfig,
 } from '~/stores/context';
 } from '~/stores/context';
 import { useSWRxSlackChannels, useIsSlackEnabled } from '~/stores/editor';
 import { useSWRxSlackChannels, useIsSlackEnabled } from '~/stores/editor';
 import { useIsMobile } from '~/stores/ui';
 import { useIsMobile } from '~/stores/ui';
@@ -28,7 +24,6 @@ import { CustomNavTab } from '../CustomNavigation/CustomNav';
 import NotAvailableForGuest from '../NotAvailableForGuest';
 import NotAvailableForGuest from '../NotAvailableForGuest';
 import Editor from '../PageEditor/Editor';
 import Editor from '../PageEditor/Editor';
 import { SlackNotification } from '../SlackNotification';
 import { SlackNotification } from '../SlackNotification';
-import { withUnstatedContainers } from '../UnstatedUtils';
 
 
 import CommentPreview from './CommentPreview';
 import CommentPreview from './CommentPreview';
 
 
@@ -47,8 +42,6 @@ const navTabMapping = {
 };
 };
 
 
 type PropsType = {
 type PropsType = {
-  appContainer: AppContainer,
-
   rendererOptions: RendererOptions,
   rendererOptions: RendererOptions,
   isForNewComment?: boolean,
   isForNewComment?: boolean,
   replyTo?: string,
   replyTo?: string,
@@ -65,10 +58,10 @@ type EditorRef = {
   terminateUploadingState: () => void,
   terminateUploadingState: () => void,
 }
 }
 
 
-const CommentEditor = (props: PropsType): JSX.Element => {
+export const CommentEditor = (props: PropsType): JSX.Element => {
 
 
   const {
   const {
-    appContainer, rendererOptions, isForNewComment, replyTo,
+    rendererOptions, isForNewComment, replyTo,
     currentCommentId, commentBody, commentCreator, onCancelButtonClicked, onCommentButtonClicked,
     currentCommentId, commentBody, commentCreator, onCancelButtonClicked, onCommentButtonClicked,
   } = props;
   } = props;
   const { data: currentUser } = useCurrentUser();
   const { data: currentUser } = useCurrentUser();
@@ -79,11 +72,7 @@ const CommentEditor = (props: PropsType): JSX.Element => {
   const { data: isMobile } = useIsMobile();
   const { data: isMobile } = useIsMobile();
   const { data: isSlackEnabled, mutate: mutateIsSlackEnabled } = useIsSlackEnabled();
   const { data: isSlackEnabled, mutate: mutateIsSlackEnabled } = useIsSlackEnabled();
   const { data: slackChannelsData } = useSWRxSlackChannels(currentPagePath);
   const { data: slackChannelsData } = useSWRxSlackChannels(currentPagePath);
-
-  const config = appContainer.getConfig();
-  const isUploadable = config.upload.image || config.upload.file;
-  const isUploadableFile = config.upload.file;
-  const isSlackConfigured = config.isSlackConfigured;
+  const { data: rendererConfig } = useRendererConfig();
 
 
   const [isReadyToUse, setIsReadyToUse] = useState(!isForNewComment);
   const [isReadyToUse, setIsReadyToUse] = useState(!isForNewComment);
   const [comment, setComment] = useState(commentBody ?? '');
   const [comment, setComment] = useState(commentBody ?? '');
@@ -295,6 +284,13 @@ const CommentEditor = (props: PropsType): JSX.Element => {
     // TODO: typescriptize Editor
     // TODO: typescriptize Editor
     const AnyEditor = Editor as any;
     const AnyEditor = Editor as any;
 
 
+    if (rendererConfig === undefined) {
+      return <></>;
+    }
+    const isUploadable = rendererConfig.upload.image || rendererConfig.upload.file;
+    const isUploadableFile = rendererConfig.upload.file;
+    const isSlackConfigured = rendererConfig.isSlackConfigured;
+
     return (
     return (
       <>
       <>
         <div className="comment-write">
         <div className="comment-write">
@@ -376,12 +372,3 @@ const CommentEditor = (props: PropsType): JSX.Element => {
   );
   );
 
 
 };
 };
-
-/**
- * Wrapper component for using unstated
- */
-const CommentEditorWrapper = withUnstatedContainers<unknown, Partial<PropsType>>(
-  CommentEditor, [AppContainer, PageContainer, EditorContainer],
-);
-
-export default CommentEditorWrapper;