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