Skip to content

Commit

Permalink
Merge pull request #270 from tnc-ca-geo/fix/289-267-comments-improvem…
Browse files Browse the repository at this point in the history
…ents-and-fixes

289/267: fix comments popover bug and improve ux
  • Loading branch information
nathanielrindlaub authored Jan 11, 2025
2 parents 9def193 + c14b47a commit 6531efc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/features/loupe/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ export const Comment = ({ comment, imageId, onChangeOpen, scrollRef }) => {
};

const onEditConfirm = () => {
// If all the comment's content is removed
// show the delete comment flow
if (editCommentText === "") {
setIsDeleteConfirm(true);
return;
}
const editCommentDto = {
id: comment._id,
imageId: imageId,
Expand All @@ -176,6 +182,25 @@ export const Comment = ({ comment, imageId, onChangeOpen, scrollRef }) => {
setIsEdit(false);
};

// Confirm edit comment using enter
// Shift + Enter makes a new line
const [isShiftDown, setIsShiftDown] = useState(false);
const handleKeyDown = (event) => {
event.stopPropagation();
if (event.key === 'Shift') {
setIsShiftDown(true);
}
if (event.key === 'Enter' && !isShiftDown) {
onEditConfirm();
event.preventDefault();
}
};
const handleKeyUp = (event) => {
if (event.key === 'Shift') {
setIsShiftDown(false);
}
};

return (
<>
<DeleteCommentAlert
Expand Down Expand Up @@ -220,8 +245,8 @@ export const Comment = ({ comment, imageId, onChangeOpen, scrollRef }) => {
<StyledTextArea
value={editCommentText}
onChange={(e) => setEditCommentText(e.target.value)}
onKeyDown={(e) => e.stopPropagation()}
onKeyDownCapture={(e) => e.stopPropagation()}
onKeyDown={(e) => handleKeyDown(e)}
onKeyUp={(e) => handleKeyUp(e)}
/>
<StyledButtonContainer>
<Button size="small" onClick={() => setIsEdit(false)}>
Expand Down
1 change: 1 addition & 0 deletions src/features/loupe/CommentsPopover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const CommentsPopover = ({ onClose, comments, imageId, onChangeActionMenu
dispatch(editComment('create', addCommentDto));
setAddCommentText('');
};

// Add comment using enter
// Shift + Enter makes a new line
const [isShiftDown, setIsShiftDown] = useState(false);
Expand Down
5 changes: 5 additions & 0 deletions src/features/loupe/ImageReviewToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ const ImageReviewToolbar = ({
}
};

// Close popover when changing images using keyboard
useEffect(() => {
setIsCommentsPopoverOpen(false);
}, [image._id]);

return (
<Toolbar>
{hasRole(userRoles, WRITE_OBJECTS_ROLES) && (
Expand Down

0 comments on commit 6531efc

Please sign in to comment.