-
-
Couldn't load subscription status.
- Fork 135
fix cancel on edit #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix cancel on edit #2592
Conversation
|
Thank you for the shout-out; and was my own limited human bafflement by the nightmare of modern client-side HTML5 codebases helpful in any way, given that you also had an AI tool review the entire codebase? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty cool! Left some nitpicks, but other than that it works correctly.
Also thank you for providing a centralized modal for confirmations
| @@ -0,0 +1,50 @@ | |||
| import Button from 'react-bootstrap/Button' | |||
|
|
|||
| export default function ConfirmModal ({ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this can be used directly instead of also creating CancelWorkConfirm and DeleteConfirm (which you didn't use but I get why you created it)
Maybe this can be called generically ObstacleModal but I'm just thinking out loud, there's no need to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which you didn't use
@pory-gone Please don't add code that is dead on arrival
You're more than welcome to refactor something, but please not while trying to fix something and not in a way that it's half-done.
components/comment.js
Outdated
| toggleEdit={e => { | ||
| if (edit) { | ||
| const editText = window.localStorage.getItem(`comment-edit-${item.id}-text`) | ||
| if (editText?.trim() && editText.trim() !== item.text.trim()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first trim (editText?.trim()) can be avoided, so that any change can count in the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh, I agree with @Soxasora
I don't think any user will care about losing an edit full of whitespace, but I think the inconsistency when the prompt shows up might confuse users. It might not be clear that it additionally checks if there's only whitespace.
| }} | ||
| schema={commentSchema} | ||
| onSubmit={onSubmit} | ||
| storageKeyPrefix={`comment-edit-${comment.id}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this somehow related to #2568?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This use local storage to save a draft of the user's edit, the draft is used to verify that there is actually text to be modified as reply.js. If you prefer not to use local storage we could open a modal when you want to close the edit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really needed and kind of out of the scope of the PR but I appreciate the fact that it makes the draft experience consistent in all typing modes, and it's also the way textboxes are handled in other places.
So that's why I didn't comment on it. If useless, it can just be removed and the obstacle modal would be there only to guard the state setting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the draft is used to verify that there is actually text to be modified as
reply.js
Ahh ok, that makes sense!
Sorry, I could have figured this out if I just looked at the other code. I tend to now just immediately ask if something is really related if it's not immediately clear since I wasted too much time in my life trying to figure out how something in someone else's code is related to a ticket or bug, just for it to end up not being related at all (and maybe even have a bug)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relevant changes look good, but I did not test them yet.
Please remove the dead code, then I will take another look, thanks
| @@ -0,0 +1,50 @@ | |||
| import Button from 'react-bootstrap/Button' | |||
|
|
|||
| export default function ConfirmModal ({ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which you didn't use
@pory-gone Please don't add code that is dead on arrival
You're more than welcome to refactor something, but please not while trying to fix something and not in a way that it's half-done.
components/comment.js
Outdated
| toggleEdit={e => { | ||
| if (edit) { | ||
| const editText = window.localStorage.getItem(`comment-edit-${item.id}-text`) | ||
| if (editText?.trim() && editText.trim() !== item.text.trim()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh, I agree with @Soxasora
I don't think any user will care about losing an edit full of whitespace, but I think the inconsistency when the prompt shows up might confuse users. It might not be clear that it additionally checks if there's only whitespace.
| }} | ||
| schema={commentSchema} | ||
| onSubmit={onSubmit} | ||
| storageKeyPrefix={`comment-edit-${comment.id}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the draft is used to verify that there is actually text to be modified as
reply.js
Ahh ok, that makes sense!
Sorry, I could have figured this out if I just looked at the other code. I tend to now just immediately ask if something is really related if it's not immediately clear since I wasted too much time in my life trying to figure out how something in someone else's code is related to a ticket or bug, just for it to end up not being related at all (and maybe even have a bug)
|
Thanks for your feedback! I removed the |
Description
fix #2568
Implemented confirmation prompt when canceling comment edit.
ConfirmModalcomponent with presets for different confirmation types.comment.js eoggleEditfunction that checks for unsaved changes inlocalStorage.comment.jsandreply.jsto use the new reusable component.storageKeyPrefixtocomment-edit.jsto properly track form changesScreenshots
2025-10-01-18-08-22.mp4
Additional Context
The implementation follows the exact same pattern used in
reply.jsto maintain consistency.the confirmation logic is handled at the parent component level
comment.jsThis implementation DOES NOT fix the multi-tab problem highlighted by @adlai, a broader refactor of the editing system would be needed, which goes beyond the scope of this issue.
Checklist
Are your changes backward compatible? Please answer below:
Yes
On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
7/10
For frontend changes: Tested on mobile, light and dark mode? Please answer below:
NaN
Did you introduce any new environment variables? If so, call them out explicitly here:
No
Did you use AI for this? If so, how much did it assist you?
I used AI to analyze the existing codebase and find interested files
Note
Cursor Bugbot is generating a summary for commit c4b2bd6. Configure here.