mirror of
https://github.com/hexastack/hexabot
synced 2025-02-19 19:08:40 +00:00
fix: unselect attachment
This commit is contained in:
parent
f7ae8682e0
commit
1aedce5207
@ -51,26 +51,25 @@ const MultipleAttachmentInput = forwardRef<
|
|||||||
const [uploadKey, setUploadKey] = useState(Date.now());
|
const [uploadKey, setUploadKey] = useState(Date.now());
|
||||||
const hasPermission = useHasPermission();
|
const hasPermission = useHasPermission();
|
||||||
const handleChange = (attachment?: IAttachment | null, index?: number) => {
|
const handleChange = (attachment?: IAttachment | null, index?: number) => {
|
||||||
if (attachment) {
|
const updatedAttachments = [...attachments];
|
||||||
const updatedAttachments = [...attachments];
|
|
||||||
|
|
||||||
|
if (attachment) {
|
||||||
if (index !== undefined) {
|
if (index !== undefined) {
|
||||||
updatedAttachments[index] = attachment.id;
|
updatedAttachments[index] = attachment.id;
|
||||||
} else {
|
} else {
|
||||||
updatedAttachments.push(attachment.id);
|
updatedAttachments.push(attachment.id);
|
||||||
}
|
}
|
||||||
setAttachments(updatedAttachments);
|
} else if (index !== undefined) {
|
||||||
onChange && onChange(updatedAttachments);
|
updatedAttachments.splice(index, 1);
|
||||||
setUploadKey(Date.now());
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
const handleRemove = (index: number) => {
|
|
||||||
const updatedAttachments = attachments.filter((_, i) => i !== index);
|
|
||||||
|
|
||||||
setAttachments(updatedAttachments);
|
setAttachments(updatedAttachments);
|
||||||
onChange && onChange(updatedAttachments);
|
onChange && onChange(updatedAttachments);
|
||||||
setUploadKey(Date.now());
|
setUploadKey(Date.now());
|
||||||
};
|
};
|
||||||
|
const handleRemove = (index: number) => {
|
||||||
|
handleChange(null, index);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box ref={ref}>
|
<Box ref={ref}>
|
||||||
|
Loading…
Reference in New Issue
Block a user