Commit a7ecdeb9 by HoMeTown

feat: 未登录的情况下发送消息的判断

parent 479b3c5f
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>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment