1- import React , { useState } from "react" ;
1+ import React , { MouseEventHandler , useState } from "react" ;
22import { Box , Button , Text , Tooltip , useDisclosure } from "@chakra-ui/react" ;
33import { BeatLoader } from "react-spinners" ;
44import { ClickPromptSmall } from "./CustomIcon" ;
55import clickPromptLogo from "@/assets/clickprompt-light.svg?url" ;
6- import { CPButtonProps , StyledBird , StyledPromptButton } from "./Button.shared" ;
6+ import { ButtonSize , StyledBird , StyledPromptButton } from "./Button.shared" ;
77import { LoggingDrawer } from "./LoggingDrawer" ;
88
9+ interface ClickPromptButtonProps {
10+ loading ?: boolean ;
11+ onClick ?: MouseEventHandler ;
12+ size ?: ButtonSize ;
13+ text : string ;
14+ children ?: React . ReactNode ;
15+ isLoggedInApi : ( ) => Promise < any > ;
16+ changeConversationNameApi : ( conversation_id : number , name : string ) => Promise < any > ;
17+ createConversationApi : ( name ?: string ) => Promise < any > ;
18+ getChatsByConversationIdApi : ( conversationId : number ) => Promise < any > ;
19+ deleteConversationApi : ( conversationId : number ) => Promise < any > ;
20+ deleteAllConversationsApi : ( ) => Promise < any > ;
21+ sendMsgWithStreamResApi : ( conversageId : number , message : string , name ?: string ) => Promise < any > ;
22+ logoutApi : ( ) => Promise < any > ;
23+ }
24+
925export type ClickPromptBirdParams = { width ?: number ; height ?: number } ;
1026
1127export function ClickPromptBird ( props : ClickPromptBirdParams ) {
@@ -15,17 +31,31 @@ export function ClickPromptBird(props: ClickPromptBirdParams) {
1531 return < StyledBird src = { clickPromptLogo } alt = "ClickPrompt Logo" width = { width } height = { height } /> ;
1632}
1733
18- export function ClickPromptButton ( props : CPButtonProps ) {
19- const [ isLoading , setIsLoading ] = useState ( props . loading ) ;
34+ export function ClickPromptButton ( {
35+ isLoggedInApi,
36+ children,
37+ size,
38+ text,
39+ onClick,
40+ loading,
41+ changeConversationNameApi,
42+ createConversationApi,
43+ getChatsByConversationIdApi,
44+ deleteConversationApi,
45+ deleteAllConversationsApi,
46+ sendMsgWithStreamResApi,
47+ logoutApi,
48+ } : ClickPromptButtonProps ) {
49+ const [ isLoading , setIsLoading ] = useState ( loading ) ;
2050 const [ isLoggedIn , setIsLoggedIn ] = useState ( false ) ;
2151 const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
2252
2353 const handleClick = async ( event : any ) => {
2454 setIsLoading ( true ) ;
25- const isLoggedIn = await props . isLoggedIn ( ) ;
55+ const isLoggedIn = await isLoggedInApi ( ) ;
2656 setIsLoggedIn ( isLoggedIn ) ;
2757 onOpen ( ) ;
28- props . onClick && props . onClick ( event ) ;
58+ onClick && onClick ( event ) ;
2959 } ;
3060
3161 const handleClose = ( ) => {
@@ -36,8 +66,9 @@ export function ClickPromptButton(props: CPButtonProps) {
3666 function NormalSize ( ) {
3767 return (
3868 < StyledPromptButton >
39- < Button colorScheme = "twitter" className = "bg-blue" onClick = { handleClick } { ...props } >
40- { props . children }
69+ { /*TODO: check ...props with what is passed in*/ }
70+ < Button colorScheme = "twitter" className = "bg-blue" onClick = { handleClick } >
71+ { children }
4172 { ! isLoading && < Text > Prompt</ Text > }
4273 { isLoading && < BeatLoader size = { 8 } color = "black" /> }
4374 </ Button >
@@ -48,8 +79,9 @@ export function ClickPromptButton(props: CPButtonProps) {
4879
4980 function SmallSize ( ) {
5081 return (
51- < Button variant = "unstyled" onClick = { handleClick } { ...props } >
52- { props . children }
82+ // TODO: check ...props with what is passed in
83+ < Button variant = "unstyled" onClick = { handleClick } >
84+ { children }
5385 < Tooltip label = "Execute ChatGPT Prompt" aria-label = "A tooltip" >
5486 < ClickPromptSmall width = { 32 } height = { 32 } />
5587 </ Tooltip >
@@ -59,10 +91,22 @@ export function ClickPromptButton(props: CPButtonProps) {
5991
6092 return (
6193 < Box >
62- { props . size !== "sm" && < NormalSize /> }
63- { props . size === "sm" && < SmallSize /> }
94+ { size !== "sm" && < NormalSize /> }
95+ { size === "sm" && < SmallSize /> }
6496
65- { LoggingDrawer ( isOpen , handleClose , isLoggedIn , props ) }
97+ { LoggingDrawer ( {
98+ isOpen,
99+ handleClose,
100+ isLoggedIn,
101+ initMessage : text ,
102+ changeConversationNameApi,
103+ createConversationApi,
104+ getChatsByConversationIdApi,
105+ deleteConversationApi,
106+ deleteAllConversationsApi,
107+ sendMsgWithStreamResApi,
108+ logoutApi,
109+ } ) }
66110 </ Box >
67111 ) ;
68112}
0 commit comments