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

useAiAssistantChatSidebar -> useAiAssistantSidebar

Shun Miyazawa 1 год назад
Родитель
Сommit
376f272c91

+ 11 - 11
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/AiAssistantSidebar.tsx

@@ -18,7 +18,7 @@ import type { AiAssistantHasId } from '../../../../interfaces/ai-assistant';
 import { SseMessageSchema, SseDetectedDiffSchema, SseFinalizedSchema } from '../../../../interfaces/editor-assistant/sse-schemas';
 import { SseMessageSchema, SseDetectedDiffSchema, SseFinalizedSchema } from '../../../../interfaces/editor-assistant/sse-schemas';
 import { MessageErrorCode, StreamErrorCode } from '../../../../interfaces/message-error';
 import { MessageErrorCode, StreamErrorCode } from '../../../../interfaces/message-error';
 import type { IThreadRelationHasId } from '../../../../interfaces/thread-relation';
 import type { IThreadRelationHasId } from '../../../../interfaces/thread-relation';
-import { useAiAssistantChatSidebar } from '../../../stores/ai-assistant';
+import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
 import { useSWRMUTxMessages } from '../../../stores/message';
 import { useSWRMUTxMessages } from '../../../stores/message';
 import { useSWRMUTxThreads } from '../../../stores/thread';
 import { useSWRMUTxThreads } from '../../../stores/thread';
 
 
@@ -54,12 +54,12 @@ type FormData = {
 type AiAssistantChatSidebarSubstanceProps = {
 type AiAssistantChatSidebarSubstanceProps = {
   aiAssistantData: AiAssistantHasId;
   aiAssistantData: AiAssistantHasId;
   threadData?: IThreadRelationHasId;
   threadData?: IThreadRelationHasId;
-  closeAiAssistantChatSidebar: () => void
+  closeAiAssistantSidebar: () => void
 }
 }
 
 
 const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceProps> = (props: AiAssistantChatSidebarSubstanceProps) => {
 const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceProps> = (props: AiAssistantChatSidebarSubstanceProps) => {
   const {
   const {
-    aiAssistantData, threadData, closeAiAssistantChatSidebar,
+    aiAssistantData, threadData, closeAiAssistantSidebar,
   } = props;
   } = props;
 
 
   const [currentThreadTitle, setCurrentThreadTitle] = useState<string | undefined>(threadData?.title);
   const [currentThreadTitle, setCurrentThreadTitle] = useState<string | undefined>(threadData?.title);
@@ -270,7 +270,7 @@ const AiAssistantChatSidebarSubstance: React.FC<AiAssistantChatSidebarSubstanceP
           <button
           <button
             type="button"
             type="button"
             className="btn btn-link p-0 border-0"
             className="btn btn-link p-0 border-0"
-            onClick={closeAiAssistantChatSidebar}
+            onClick={closeAiAssistantSidebar}
           >
           >
             <span className="material-symbols-outlined">close</span>
             <span className="material-symbols-outlined">close</span>
           </button>
           </button>
@@ -433,16 +433,16 @@ export const AiAssistantSidebar: FC = memo((): JSX.Element => {
   const sidebarRef = useRef<HTMLDivElement>(null);
   const sidebarRef = useRef<HTMLDivElement>(null);
   const sidebarScrollerRef = useRef<HTMLDivElement>(null);
   const sidebarScrollerRef = useRef<HTMLDivElement>(null);
 
 
-  const { data: aiAssistantChatSidebarData, close: closeAiAssistantChatSidebar } = useAiAssistantChatSidebar();
+  const { data: aiAssistantSidebarData, close: closeAiAssistantSidebar } = useAiAssistantSidebar();
 
 
-  const aiAssistantData = aiAssistantChatSidebarData?.aiAssistantData;
-  const threadData = aiAssistantChatSidebarData?.threadData;
-  const isOpened = aiAssistantChatSidebarData?.isOpened && aiAssistantData != null;
+  const aiAssistantData = aiAssistantSidebarData?.aiAssistantData;
+  const threadData = aiAssistantSidebarData?.threadData;
+  const isOpened = aiAssistantSidebarData?.isOpened && aiAssistantData != null;
 
 
   useEffect(() => {
   useEffect(() => {
     const handleClickOutside = (event: MouseEvent) => {
     const handleClickOutside = (event: MouseEvent) => {
       if (isOpened && sidebarRef.current && !sidebarRef.current.contains(event.target as Node)) {
       if (isOpened && sidebarRef.current && !sidebarRef.current.contains(event.target as Node)) {
-        closeAiAssistantChatSidebar();
+        closeAiAssistantSidebar();
       }
       }
     };
     };
 
 
@@ -450,7 +450,7 @@ export const AiAssistantSidebar: FC = memo((): JSX.Element => {
     return () => {
     return () => {
       document.removeEventListener('mousedown', handleClickOutside);
       document.removeEventListener('mousedown', handleClickOutside);
     };
     };
-  }, [closeAiAssistantChatSidebar, isOpened]);
+  }, [closeAiAssistantSidebar, isOpened]);
 
 
   if (!isOpened) {
   if (!isOpened) {
     return <></>;
     return <></>;
@@ -470,7 +470,7 @@ export const AiAssistantSidebar: FC = memo((): JSX.Element => {
         <AiAssistantChatSidebarSubstance
         <AiAssistantChatSidebarSubstance
           threadData={threadData}
           threadData={threadData}
           aiAssistantData={aiAssistantData}
           aiAssistantData={aiAssistantData}
-          closeAiAssistantChatSidebar={closeAiAssistantChatSidebar}
+          closeAiAssistantSidebar={closeAiAssistantSidebar}
         />
         />
       </SimpleBar>
       </SimpleBar>
     </div>
     </div>

+ 4 - 4
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/MessageCard.tsx

@@ -6,7 +6,7 @@ import ReactMarkdown from 'react-markdown';
 
 
 import { NextLink } from '~/components/ReactMarkdownComponents/NextLink';
 import { NextLink } from '~/components/ReactMarkdownComponents/NextLink';
 
 
-import { useAiAssistantChatSidebar } from '../../../stores/ai-assistant';
+import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
 
 
 import styles from './MessageCard.module.scss';
 import styles from './MessageCard.module.scss';
 
 
@@ -27,11 +27,11 @@ const UserMessageCard = ({ children }: { children: string }): JSX.Element => (
 const assistantMessageCardModuleClass = styles['assistant-message-card'] ?? '';
 const assistantMessageCardModuleClass = styles['assistant-message-card'] ?? '';
 
 
 const NextLinkWrapper = (props: LinkProps & {children: string, href: string}): JSX.Element => {
 const NextLinkWrapper = (props: LinkProps & {children: string, href: string}): JSX.Element => {
-  const { close: closeAiAssistantChatSidebar } = useAiAssistantChatSidebar();
+  const { close: closeAiAssistantSidebar } = useAiAssistantSidebar();
 
 
   const onClick = useCallback(() => {
   const onClick = useCallback(() => {
-    closeAiAssistantChatSidebar();
-  }, [closeAiAssistantChatSidebar]);
+    closeAiAssistantSidebar();
+  }, [closeAiAssistantSidebar]);
 
 
   return (
   return (
     <NextLink href={props.href} onClick={onClick} className="link-primary">
     <NextLink href={props.href} onClick={onClick} className="link-primary">

+ 4 - 4
apps/app/src/features/openai/client/components/AiAssistant/OpenDefaultAiAssistantButton.tsx

@@ -6,7 +6,7 @@ import { NotAvailable } from '~/client/components/NotAvailable';
 import { NotAvailableForGuest } from '~/client/components/NotAvailableForGuest';
 import { NotAvailableForGuest } from '~/client/components/NotAvailableForGuest';
 import { useIsAiEnabled } from '~/stores-universal/context';
 import { useIsAiEnabled } from '~/stores-universal/context';
 
 
-import { useAiAssistantChatSidebar, useSWRxAiAssistants } from '../../stores/ai-assistant';
+import { useAiAssistantSidebar, useSWRxAiAssistants } from '../../stores/ai-assistant';
 
 
 import styles from './OpenDefaultAiAssistantButton.module.scss';
 import styles from './OpenDefaultAiAssistantButton.module.scss';
 
 
@@ -14,7 +14,7 @@ const OpenDefaultAiAssistantButton = (): JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
   const { data: isAiEnabled } = useIsAiEnabled();
   const { data: isAiEnabled } = useIsAiEnabled();
   const { data: aiAssistantData } = useSWRxAiAssistants();
   const { data: aiAssistantData } = useSWRxAiAssistants();
-  const { open: openAiAssistantChatSidebar } = useAiAssistantChatSidebar();
+  const { open: openAiAssistantSidebar } = useAiAssistantSidebar();
 
 
   const defaultAiAssistant = useMemo(() => {
   const defaultAiAssistant = useMemo(() => {
     if (aiAssistantData == null) {
     if (aiAssistantData == null) {
@@ -30,8 +30,8 @@ const OpenDefaultAiAssistantButton = (): JSX.Element => {
       return;
       return;
     }
     }
 
 
-    openAiAssistantChatSidebar(defaultAiAssistant);
-  }, [defaultAiAssistant, openAiAssistantChatSidebar]);
+    openAiAssistantSidebar(defaultAiAssistant);
+  }, [defaultAiAssistant, openAiAssistantSidebar]);
 
 
   if (!isAiEnabled) {
   if (!isAiEnabled) {
     return <></>;
     return <></>;

+ 3 - 3
apps/app/src/features/openai/client/components/AiAssistant/Sidebar/AiAssistantTree.tsx

@@ -14,7 +14,7 @@ import { AiAssistantShareScope, type AiAssistantHasId } from '../../../../interf
 import { determineShareScope } from '../../../../utils/determine-share-scope';
 import { determineShareScope } from '../../../../utils/determine-share-scope';
 import { deleteAiAssistant, setDefaultAiAssistant } from '../../../services/ai-assistant';
 import { deleteAiAssistant, setDefaultAiAssistant } from '../../../services/ai-assistant';
 import { deleteThread } from '../../../services/thread';
 import { deleteThread } from '../../../services/thread';
-import { useAiAssistantChatSidebar, useAiAssistantManagementModal } from '../../../stores/ai-assistant';
+import { useAiAssistantSidebar, useAiAssistantManagementModal } from '../../../stores/ai-assistant';
 import { useSWRMUTxThreads, useSWRxThreads } from '../../../stores/thread';
 import { useSWRMUTxThreads, useSWRxThreads } from '../../../stores/thread';
 
 
 import styles from './AiAssistantTree.module.scss';
 import styles from './AiAssistantTree.module.scss';
@@ -298,7 +298,7 @@ type AiAssistantTreeProps = {
 
 
 export const AiAssistantTree: React.FC<AiAssistantTreeProps> = ({ aiAssistants, onUpdated, onDeleted }) => {
 export const AiAssistantTree: React.FC<AiAssistantTreeProps> = ({ aiAssistants, onUpdated, onDeleted }) => {
   const { data: currentUser } = useCurrentUser();
   const { data: currentUser } = useCurrentUser();
-  const { open: openAiAssistantChatSidebar } = useAiAssistantChatSidebar();
+  const { open: openAiAssistantSidebar } = useAiAssistantSidebar();
   const { open: openAiAssistantManagementModal } = useAiAssistantManagementModal();
   const { open: openAiAssistantManagementModal } = useAiAssistantManagementModal();
 
 
   return (
   return (
@@ -309,7 +309,7 @@ export const AiAssistantTree: React.FC<AiAssistantTreeProps> = ({ aiAssistants,
           currentUser={currentUser}
           currentUser={currentUser}
           aiAssistant={assistant}
           aiAssistant={assistant}
           onEditClick={openAiAssistantManagementModal}
           onEditClick={openAiAssistantManagementModal}
-          onItemClick={openAiAssistantChatSidebar}
+          onItemClick={openAiAssistantSidebar}
           onUpdated={onUpdated}
           onUpdated={onUpdated}
           onDeleted={onDeleted}
           onDeleted={onDeleted}
         />
         />

+ 6 - 6
apps/app/src/features/openai/client/stores/ai-assistant.tsx

@@ -55,13 +55,13 @@ export const useSWRxAiAssistants = (): SWRResponse<AccessibleAiAssistantsHasId,
 };
 };
 
 
 
 
-type AiAssistantChatSidebarStatus = {
+type AiAssistantSidebarStatus = {
   isOpened: boolean,
   isOpened: boolean,
   aiAssistantData?: AiAssistantHasId,
   aiAssistantData?: AiAssistantHasId,
   threadData?: IThreadRelationHasId,
   threadData?: IThreadRelationHasId,
 }
 }
 
 
-type AiAssistantChatSidebarUtils = {
+type AiAssistantSidebarUtils = {
   open(
   open(
     aiAssistantData: AiAssistantHasId,
     aiAssistantData: AiAssistantHasId,
     threadData?: IThreadRelationHasId,
     threadData?: IThreadRelationHasId,
@@ -69,11 +69,11 @@ type AiAssistantChatSidebarUtils = {
   close(): void
   close(): void
 }
 }
 
 
-export const useAiAssistantChatSidebar = (
-    status?: AiAssistantChatSidebarStatus,
-): SWRResponse<AiAssistantChatSidebarStatus, Error> & AiAssistantChatSidebarUtils => {
+export const useAiAssistantSidebar = (
+    status?: AiAssistantSidebarStatus,
+): SWRResponse<AiAssistantSidebarStatus, Error> & AiAssistantSidebarUtils => {
   const initialStatus = { isOpened: false };
   const initialStatus = { isOpened: false };
-  const swrResponse = useSWRStatic<AiAssistantChatSidebarStatus, Error>('AiAssistantChatSidebar', status, { fallbackData: initialStatus });
+  const swrResponse = useSWRStatic<AiAssistantSidebarStatus, Error>('AiAssistantSidebar', status, { fallbackData: initialStatus });
 
 
   return {
   return {
     ...swrResponse,
     ...swrResponse,