1
1
import TextareaAutosize from "react-textarea-autosize" ;
2
- import { SendHorizonal , Redo2 } from "lucide-react" ;
2
+ import { SendHorizonal , AlertTriangle , RotateCcw } from "lucide-react" ;
3
3
import { useChat } from "../contexts/Controller" ;
4
4
import { useRef , useState } from "react" ;
5
- import { Tooltip , TooltipContent , TooltipTrigger } from "./ToolTip" ;
6
5
import { getId , isEmpty } from "@lib/utils/utils" ;
7
6
import now from "@lib/utils/timenow" ;
8
7
import { useDocumentDirection } from "@lib/hooks/useDocumentDirection" ;
9
8
import { VoiceRecorder } from "./VoiceRecorder" ;
10
9
import { useInitialData } from "@lib/hooks/useInitialData" ;
10
+ import {
11
+ Dialog ,
12
+ DialogClose ,
13
+ DialogContent ,
14
+ DialogHeader ,
15
+ DialogTrigger ,
16
+ } from "./Dialog" ;
17
+ import { Button } from "./Button" ;
11
18
12
19
function MessageSuggestions ( ) {
13
20
const { data } = useInitialData ( ) ;
@@ -38,13 +45,44 @@ function MessageSuggestions() {
38
45
</ >
39
46
) ;
40
47
}
41
- // curl --location 'http://localhost:8888/backend/chat/transcribe' \
42
- // --form 'file=@"/Users/gharbat/Downloads/Neets.ai-example-us-female-2.mp3"'
43
-
48
+ function ResetButtonWithConfirmation ( ) {
49
+ const { reset } = useChat ( ) ;
50
+ const [ open , setOpen ] = useState ( false ) ;
51
+ return (
52
+ < Dialog open = { open } onOpenChange = { setOpen } >
53
+ < DialogTrigger >
54
+ < RotateCcw size = { 20 } />
55
+ </ DialogTrigger >
56
+ < DialogContent >
57
+ < DialogHeader >
58
+ < div className = "mx-auto flex flex-col items-center justify-center" >
59
+ < span className = "text-rose-500" >
60
+ < AlertTriangle className = "size-10" />
61
+ </ span >
62
+ < h2 > are you sure?</ h2 >
63
+ </ div >
64
+ </ DialogHeader >
65
+ < div className = "flex flex-row items-center justify-center gap-2" >
66
+ < Button
67
+ asChild
68
+ variant = "destructive"
69
+ className = "font-semibold"
70
+ onClick = { reset }
71
+ >
72
+ < DialogClose > Yes, reset</ DialogClose >
73
+ </ Button >
74
+ < Button asChild variant = "secondary" className = "font-semibold" >
75
+ < DialogClose > No, Cancel</ DialogClose >
76
+ </ Button >
77
+ </ div >
78
+ </ DialogContent >
79
+ </ Dialog >
80
+ ) ;
81
+ }
44
82
function ChatInputFooter ( ) {
45
83
const [ input , setInput ] = useState ( "" ) ;
46
84
const textAreaRef = useRef < HTMLTextAreaElement > ( null ) ;
47
- const { sendMessage, reset , messages } = useChat ( ) ;
85
+ const { sendMessage } = useChat ( ) ;
48
86
const { loading } = useChat ( ) ;
49
87
const canSend = input . trim ( ) . length > 0 ;
50
88
const { direction } = useDocumentDirection ( ) ;
@@ -68,14 +106,15 @@ function ChatInputFooter() {
68
106
}
69
107
}
70
108
return (
71
- < footer className = " p-2 flex w-full flex-col gap-2" >
109
+ < footer className = "p-2 flex w-full flex-col gap-2" >
72
110
< MessageSuggestions />
73
111
< div className = "w-full flex items-center ring-[#334155]/60 transition-colors justify-between ring-1 overflow-hidden focus-within:ring-primary gap-2 bg-accent p-2 rounded-2xl" >
74
- < div className = " flex-1" >
112
+ < div className = "flex-1" >
75
113
< TextareaAutosize
76
114
dir = "auto"
77
115
ref = { textAreaRef }
78
116
autoFocus = { true }
117
+ placeholder = "_"
79
118
onKeyDown = { ( event ) => {
80
119
if ( event . key === "Enter" && ! event . shiftKey ) {
81
120
event . preventDefault ( ) ;
@@ -87,25 +126,14 @@ function ChatInputFooter() {
87
126
rows = { 1 }
88
127
value = { input }
89
128
onChange = { handleTextareaChange }
90
- className = " w-full resize-none bg-transparent focus-visible:outline-none border-none focus:outline-none focus:border-none scrollbar-thin leading-tight whitespace-pre-wrap py-1.5 px-4 placeholder:align-middle overflow-auto outline-none text-accent2 text-[14px] placeholder:text-xs font-normal"
129
+ className = " w-full resize-none bg-transparent focus-visible:outline-none border-none focus:outline-none focus:border-none scrollbar-thin leading-tight whitespace-pre-wrap py-1.5 px-4 placeholder:align-middle overflow-auto outline-none text-accent2 text-[14px] placeholder:text-xs font-normal"
91
130
/>
92
131
</ div >
93
132
< div
94
133
dir = { direction }
95
- className = "flex items-center justify-center gap-2 h-fit px-2 text-lg"
134
+ className = "flex items-center justify-center gap-2 h-fit px-2 text-lg"
96
135
>
97
- < Tooltip >
98
- < TooltipTrigger asChild hidden >
99
- < button
100
- onClick = { reset }
101
- className = " text-xl disabled: opacity-40 disabled: pointer-events-none disabled: cursor-not-allowed text-[#5e5c5e] transition-all"
102
- disabled = { ! ( messages . length > 0 ) }
103
- >
104
- < Redo2 className = "rtl: rotate-180" />
105
- </ button >
106
- </ TooltipTrigger >
107
- < TooltipContent > reset chat</ TooltipContent >
108
- </ Tooltip >
136
+ < ResetButtonWithConfirmation />
109
137
< VoiceRecorder onSuccess = { ( text ) => setInput ( text ) } />
110
138
< button
111
139
onClick = { handleInputSubmit }
0 commit comments