-
-
Notifications
You must be signed in to change notification settings - Fork 527
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
Don't ask user about discarding message/losing changes if they haven't done anything in editor #1633
Don't ask user about discarding message/losing changes if they haven't done anything in editor #1633
Conversation
I noticed that there are also some polls that you can cancel and see the dialog but I'm not sure how to create a poll if you tell me how to test this I will also remove the dialog when they are empty. |
This is good first step, but what about attachments or initial value being quote of other reply? |
On thread pages there’s „add poll” button next to repky button. |
Thanks! |
I will make an update for this case too :) |
@rafalp Hello I added a few updates. Now it should have removed discard changes text for polls where the user has not added any data, and quote replies where there is nothing in the editor aside from the initial quote. |
@rafalp I've also added checks to make sure discard changes message is only skipped when there are no attachments, or in the case of private threads, when there are no attachments or recipients. Hopefully this covers it all, if anything is missing don't hesitate to message :) |
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've left some notes.
@@ -60,6 +60,8 @@ export default class extends Form { | |||
} | |||
|
|||
loadSuccess = (data) => { | |||
this.state.originalPost = data.post |
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.
Question: does this need to be a state var? Can't we put this into class property?
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.
Sure thing will update.
|
||
// Nothing added to the poll so no changes to discard | ||
const nothingAddedToPoll = | ||
pollData.question === "" && |
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.
Why use pollData
instead of this.state...
like other places do? TBH I like that approach better.
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.
True that. Not need to overcomplicate with another variable. Will remove.
const nothingAddedToPoll = | ||
pollData.question === "" && | ||
pollData.choices[0].label === "" && | ||
pollData.choices[1].label === "" && |
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.
What if choices are undefined? Or if there are more than default 2?
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.
Mmm. I think for this I will add a check in case the choices array's length is more than 0 -and if so iterate through the array checking if the labels are empty.
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 is the way.
|
||
// If only the quote text is on editor user didn't add anything | ||
// so no changes to discard | ||
const onlyQuoteTextInEditor = |
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.
Seems flaky but still good enough for first iteration.
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 think for this I will add a quoteText class var where I will save the original replay and compare it to that is on the editor at the time of canceling.
Ok I will make an update with the required changes. |
@rafalp Ok I've added changes. Please check again. |
// so no changes to discard | ||
const onlyQuoteTextInEditor = this.state.post === this.quoteText | ||
|
||
if (editorEmpty || onlyQuoteTextInEditor) { |
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.
Shouldn't this be &&
? this.state.attachments.length === 1
will cause editorEmpty
to be false, but if both post
and quoteText
are empty strings, onlyQuoteTextInEditor
will be true
?
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've updated the conditional to make it simpler. Now it checks if onlyQuoteTextInEditor
and this.state.attachments === 0
.
Did you format the code with prettier? I think those multiline conditions should be wrapped in parenthesis by it ( |
For me it's removing the parenthesis on save. |
You are correct, I am wrapping those in |
Ok, I added parenthesis around the conditionals. |
@@ -67,6 +67,19 @@ export default class extends Form { | |||
onCancel = () => { | |||
let cancel = false | |||
|
|||
// Nothing added to the poll so no changes to discard |
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.
Common semantics for forms are calling them either "clean" (or "empty)" (no changes made by the user) or "dirty" (changes made by the user).
Can you update this variable to formEmpty
?
@@ -88,6 +88,17 @@ export default class extends Form { | |||
} | |||
|
|||
onCancel = () => { | |||
const editorEmpty = !!( |
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.
const editorEmpty = !!( | |
const formEmpty = !!( |
@@ -40,6 +40,17 @@ export default class extends Form { | |||
} | |||
|
|||
onCancel = () => { | |||
const editorEmpty = !!( |
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.
const editorEmpty = !!( | |
const formEmpty = !!( |
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.
Done.
|
I was running |
Please rebase and I'll merge this <3 |
Rebasing branch no-discarding-message-when-editor-empty with main branch changes.
and feature branch changes.
…all choices labels are empty.
44f55f8
to
548ad4b
Compare
@rafalp Please check. I'm not so sure I should have all the commits repeated after the last push. I also used force push after rebasing. I couldn't find a way to fix the git In any case I checked and all my changes were relatively simple and on only a few files. Worst case scenario I can create a new branch that has all the current changes from origin and re-add my changes there and do another PR. |
Trick to rebase is that you pull main branch first to make sure it has latest changes. Then on your branch you do But at the end I'll squash your changes on merge, so those all commits will be rolled up into one on |
Ok. Should I do anything more on my side or? :) |
Thank you! |
Glad to help! |
Hello @rafalp ,
I made changes to fix #1540
I added a conditional to the relevant
onCancel
functions:This way when discarding a thread, a private thread, editing or replying the dialog will only appear post or title have a lenght other than 0.