Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
a7ecdeb9
Commit
a7ecdeb9
authored
Aug 07, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 未登录的情况下发送消息的判断
parent
479b3c5f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
src/components/ChatEditor/index.tsx
+15
-0
No files found.
src/components/ChatEditor/index.tsx
View file @
a7ecdeb9
import
React
,
{
useEffect
,
useRef
,
useState
}
from
'react'
import
React
,
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
AnimatePresence
,
motion
}
from
'framer-motion'
import
{
AnimatePresence
,
motion
}
from
'framer-motion'
import
{
Button
}
from
'@nextui-org/react'
import
{
Button
}
from
'@nextui-org/react'
import
{
useLocalStorageState
,
useToggle
}
from
'ahooks'
import
{
LoginModal
}
from
'../LoginModal'
import
SendIcon
from
'@/assets/svg/send.svg?react'
import
SendIcon
from
'@/assets/svg/send.svg?react'
interface
EditorProps
{
interface
EditorProps
{
...
@@ -15,6 +17,11 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
...
@@ -15,6 +17,11 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
const
editorRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
editorRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
[
currentPlaceholder
,
setCurrentPlaceholder
]
=
useState
(
0
)
const
[
currentPlaceholder
,
setCurrentPlaceholder
]
=
useState
(
0
)
const
intervalRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
intervalRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
[
token
]
=
useLocalStorageState
<
string
|
undefined
>
(
'__TOKEN__'
,
{
defaultValue
:
''
,
listenStorageChange
:
true
,
})
const
[
isOpenLoginModal
,
isOpenLoginModalActions
]
=
useToggle
()
const
startAnimation
=
()
=>
{
const
startAnimation
=
()
=>
{
intervalRef
.
current
=
setInterval
(()
=>
{
intervalRef
.
current
=
setInterval
(()
=>
{
...
@@ -40,6 +47,10 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
...
@@ -40,6 +47,10 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
}
}
const
handleSubmit
=
()
=>
{
const
handleSubmit
=
()
=>
{
if
(
!
token
)
{
isOpenLoginModalActions
.
setRight
()
return
}
if
(
content
.
trim
())
{
if
(
content
.
trim
())
{
onSubmit
?.(
content
.
trim
())
onSubmit
?.(
content
.
trim
())
setContent
(
''
)
setContent
(
''
)
...
@@ -58,6 +69,9 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
...
@@ -58,6 +69,9 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
e
.
preventDefault
()
// 防止删除最后一个字符后继续删除
e
.
preventDefault
()
// 防止删除最后一个字符后继续删除
}
}
}
}
const
handleCloseLoginModal
=
()
=>
{
isOpenLoginModalActions
.
setLeft
()
}
useEffect
(()
=>
{
useEffect
(()
=>
{
startAnimation
()
startAnimation
()
...
@@ -120,6 +134,7 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
...
@@ -120,6 +134,7 @@ const Editor: React.FC<EditorProps> = ({ onChange, onFocus, onSubmit, placeholde
)
}
)
}
</
AnimatePresence
>
</
AnimatePresence
>
</
div
>
</
div
>
<
LoginModal
onClose=
{
handleCloseLoginModal
}
isOpen=
{
isOpenLoginModal
}
/>
</
div
>
</
div
>
)
)
}
}
...
...
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