|
|
@ -1,7 +1,9 @@
|
|
|
|
'use client';
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
|
|
/** 子评论输入框 */
|
|
|
|
/** 子评论输入框 */
|
|
|
|
import { useState, useRef, useMemo, useEffect } from 'react';
|
|
|
|
import { useState, useRef, useEffect } from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { debounce } from 'lodash';
|
|
|
|
|
|
|
|
|
|
|
|
import { Avatar, Button } from '@/components';
|
|
|
|
import { Avatar, Button } from '@/components';
|
|
|
|
|
|
|
|
|
|
|
@ -18,15 +20,15 @@ export default function SubCommentForm({ nickName, avatar, className, onSubmit,
|
|
|
|
const [value, setValue] = useState<string>('');
|
|
|
|
const [value, setValue] = useState<string>('');
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
|
|
|
|
|
|
|
|
const btnDisabled = useMemo(() => {
|
|
|
|
|
|
|
|
return loading && !value.trim();
|
|
|
|
|
|
|
|
}, [loading, value]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
if (!value) return;
|
|
|
|
if (!value.trim()) return;
|
|
|
|
|
|
|
|
|
|
|
|
setLoading(true);
|
|
|
|
setLoading(true);
|
|
|
|
const res = await onSubmit(value);
|
|
|
|
const res = await onSubmit(value);
|
|
|
|
if (res) onClose();
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
onClose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setLoading(false);
|
|
|
|
setLoading(false);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -35,7 +37,7 @@ export default function SubCommentForm({ nickName, avatar, className, onSubmit,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<form className={`${className}`} onBlur={onClose}>
|
|
|
|
<form className={`${className}`}>
|
|
|
|
<div className={`flex flex-row items-center`}>
|
|
|
|
<div className={`flex flex-row items-center`}>
|
|
|
|
<Avatar size={40} src={avatar} className="mr-[6px]" />
|
|
|
|
<Avatar size={40} src={avatar} className="mr-[6px]" />
|
|
|
|
<input
|
|
|
|
<input
|
|
|
@ -51,9 +53,9 @@ export default function SubCommentForm({ nickName, avatar, className, onSubmit,
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
type="primary"
|
|
|
|
disabled={btnDisabled}
|
|
|
|
disabled={loading || !value.trim()}
|
|
|
|
className="w-[80px] h-[35px] mt-[15px] rounded-[16px] text-[13px] leading-[18.2px]"
|
|
|
|
className="w-[80px] h-[35px] my-[15px] rounded-[16px] text-[13px] leading-[18.2px]"
|
|
|
|
onClick={handleSubmit}
|
|
|
|
onClick={debounce(handleSubmit)}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
确定
|
|
|
|
确定
|
|
|
|
</Button>
|
|
|
|
</Button>
|
|
|
|