Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
70a187cc
Unverified
Commit
70a187cc
authored
Mar 08, 2023
by
boojack
Committed by
GitHub
Mar 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update ask AI trigger (#1316)
parent
390e29f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
16 deletions
+24
-16
AskAIDialog.tsx
web/src/components/AskAIDialog.tsx
+24
-16
No files found.
web/src/components/AskAIDialog.tsx
View file @
70a187cc
...
...
@@ -20,6 +20,7 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
const
fetchingState
=
useLoading
(
false
);
const
[
historyList
,
setHistoryList
]
=
useState
<
History
[]
>
([]);
const
[
isEnabled
,
setIsEnabled
]
=
useState
<
boolean
>
(
true
);
const
[
question
,
setQuestion
]
=
useState
<
string
>
(
""
);
useEffect
(()
=>
{
api
.
checkOpenAIEnabled
().
then
(({
data
})
=>
{
...
...
@@ -33,21 +34,20 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
destroy
();
};
const
handleQuestionTextareaKeyDown
=
async
(
event
:
React
.
KeyboardEvent
<
HTMLTextAreaElement
>
)
=>
{
if
(
event
.
key
===
"Enter"
)
{
event
.
preventDefault
();
const
question
=
event
.
currentTarget
.
value
;
event
.
currentTarget
.
value
=
""
;
const
handleQuestionTextareaChange
=
async
(
event
:
React
.
ChangeEvent
<
HTMLTextAreaElement
>
)
=>
{
setQuestion
(
event
.
currentTarget
.
value
);
};
fetchingState
.
setLoading
();
try
{
await
askQuestion
(
question
);
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toastHelper
.
error
(
error
.
response
.
data
.
error
);
}
fetchingState
.
setFinish
();
const
handleSendQuestionButtonClick
=
async
()
=>
{
fetchingState
.
setLoading
();
try
{
await
askQuestion
(
question
);
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toastHelper
.
error
(
error
.
response
.
data
.
error
);
}
setQuestion
(
""
);
fetchingState
.
setFinish
();
};
const
askQuestion
=
async
(
question
:
string
)
=>
{
...
...
@@ -79,7 +79,13 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
</
button
>
</
div
>
<
div
className=
"dialog-content-container !w-112 max-w-full"
>
<
Textarea
className=
"w-full"
placeholder=
"Ask anything…"
onKeyDown=
{
handleQuestionTextareaKeyDown
}
/>
<
div
className=
"w-full relative"
>
<
Textarea
className=
"w-full"
placeholder=
"Ask anything…"
value=
{
question
}
onChange=
{
handleQuestionTextareaChange
}
/>
<
Icon
.
Send
className=
"cursor-pointer w-7 p-1 h-auto rounded-md bg-gray-100 dark:bg-zinc-800 absolute right-2 bottom-1.5 shadow hover:opacity-80"
onClick=
{
handleSendQuestionButtonClick
}
/>
</
div
>
{
fetchingState
.
isLoading
&&
(
<
p
className=
"w-full py-2 mt-4 flex flex-row justify-center items-center"
>
<
Icon
.
Loader
className=
"w-5 h-auto animate-spin"
/>
...
...
@@ -88,10 +94,12 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
{
historyList
.
map
((
history
,
index
)
=>
(
<
div
key=
{
index
}
className=
"w-full flex flex-col justify-start items-start mt-4 space-y-2"
>
<
div
className=
"w-full flex flex-row justify-start items-start pr-6"
>
<
span
className=
"word-break rounded shadow px-3 py-2 opacity-80 bg-gray-100 dark:bg-zinc-700"
>
{
history
.
question
}
</
span
>
<
span
className=
"word-break rounded-lg rounded-tl-none px-3 py-2 opacity-80 bg-gray-100 dark:bg-zinc-700"
>
{
history
.
question
}
</
span
>
</
div
>
<
div
className=
"w-full flex flex-row justify-end items-start pl-8 space-x-2"
>
<
div
className=
"memo-content-wrapper !w-auto flex flex-col justify-start items-start rounded
shadow
px-3 py-2 bg-gray-100 dark:bg-zinc-700"
>
<
div
className=
"memo-content-wrapper !w-auto flex flex-col justify-start items-start rounded
-lg rounded-tr-none
px-3 py-2 bg-gray-100 dark:bg-zinc-700"
>
<
div
className=
"memo-content-text"
>
{
marked
(
history
.
answer
)
}
</
div
>
</
div
>
<
Icon
.
Bot
className=
"mt-2 flex-shrink-0 mr-1 w-6 h-auto opacity-80"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment