Skip to content

Commit

Permalink
Implement delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Nov 19, 2024
1 parent 0a8b671 commit d8b397d
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ const { Dragger } = Upload;

type UploadFileProps = QuestionItemProps;

type ValueAttachment = { value: { Attachment: Attachment } };

export function UploadFileControl({ parentPath, questionItem }: UploadFileProps) {
const { linkId, helpText, repeats } = questionItem;
const fieldName = [...parentPath, linkId];
const { formItem, value, onChange } = useFieldController(fieldName, questionItem);
/* const ref = useRef<Record<string, string>>({}); */
const uid = useRef<Record<string, string>>({});

const initialFileList: Array<UploadFile> = (value ?? []).map((v: { value: { Attachment: Attachment } }) => {
const initialFileList: Array<UploadFile> = (value ?? []).map((v: ValueAttachment) => {
const url = v.value.Attachment.url!;
const file: UploadFile = {
uid: url,
Expand Down Expand Up @@ -71,9 +73,9 @@ export function UploadFileControl({ parentPath, questionItem }: UploadFileProps)
}
};
const onRemove = (file: UploadFile) => {
console.log(file);
onChange([]);
setFileList([]);
const filename = uid.current[file.uid] ?? file.uid;
onChange((value ?? []).filter(({ value }: ValueAttachment) => value.Attachment.url !== filename));
setFileList((files) => files.filter((f) => f.uid !== file.uid));
};

return (
Expand Down

0 comments on commit d8b397d

Please sign in to comment.