Skip to content

Commit

Permalink
fix(web): fix commit modal drop handler
Browse files Browse the repository at this point in the history
- Move drop handler hook outside of callback
- Prioritize new commit value over old one, not vice versa
  • Loading branch information
LordTermor committed Jun 26, 2024
1 parent 1817e5c commit f885916
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions web/src/modals/CommitModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ export const CommitModal = forwardRef<HTMLDialogElement, CommitModalProps>(
props.onCommitSubmit(section, commit);
}, [commit, props.onSubmit]);

const packageDropHandler = usePackageDropHandler(section, (_, commit) =>
setCommit((prevCommit) => {
const newCommit = new Map(prevCommit);

commit.forEach((value, key) => {
newCommit.set(key, {
...commit.get(key),
...value
});
});

return newCommit;
})
);

return createPortal(
<Modal ref={ref} className="w-11/12 max-w-5xl" {...props}>
<Modal.Header>
Expand All @@ -65,23 +80,7 @@ export const CommitModal = forwardRef<HTMLDialogElement, CommitModalProps>(
/>
</div>
</Modal.Header>
<Dropzone
noClick={true}
onDrop={usePackageDropHandler(section, (_, commit) =>
setCommit((prevCommit) => {
const newCommit = new Map(prevCommit);

commit.forEach((value, key) => {
newCommit.set(key, {
...value,
...commit.get(key)
});
});

return newCommit;
})
)}
>
<Dropzone noClick={true} onDrop={packageDropHandler}>
{({ getRootProps, getInputProps }) => (
<Modal.Body {...getRootProps()}>
<input {...getInputProps()} />
Expand Down

0 comments on commit f885916

Please sign in to comment.