Skip to content
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

Merged
merged 21 commits into from
Jul 11, 2023

Conversation

manuel12
Copy link
Contributor

Hello @rafalp ,

I made changes to fix #1540

I added a conditional to the relevant onCancel functions:

const editorEmpty =
        this.state.post.length === 0 && this.state.title.length === 0

if (editorEmpty) {
    this.minimize()
    posting.close()
    return
}

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.

@manuel12
Copy link
Contributor Author

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.

@rafalp
Copy link
Owner

rafalp commented Jun 23, 2023

This is good first step, but what about attachments or initial value being quote of other reply?

@rafalp
Copy link
Owner

rafalp commented Jun 23, 2023

On thread pages there’s „add poll” button next to repky button.

@manuel12
Copy link
Contributor Author

On thread pages there’s „add poll” button next to repky button.

Thanks!

@manuel12
Copy link
Contributor Author

On thread pages there’s „add poll” button next to repky button.

I will make an update for this case too :)

@manuel12
Copy link
Contributor Author

@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.

@manuel12
Copy link
Contributor Author

@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 :)

Copy link
Owner

@rafalp rafalp left a 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
Copy link
Owner

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?

Copy link
Contributor Author

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 === "" &&
Copy link
Owner

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.

Copy link
Contributor Author

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 === "" &&
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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 =
Copy link
Owner

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.

Copy link
Contributor Author

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.

@manuel12
Copy link
Contributor Author

Ok I will make an update with the required changes.

@manuel12
Copy link
Contributor Author

@rafalp Ok I've added changes. Please check again.

@rafalp rafalp changed the title [FIX] Don't ask user about discarding message/losing changes if they haven't done anything in editor Don't ask user about discarding message/losing changes if they haven't done anything in editor Jun 28, 2023
@rafalp rafalp added this to the 0.37 milestone Jun 28, 2023
// so no changes to discard
const onlyQuoteTextInEditor = this.state.post === this.quoteText

if (editorEmpty || onlyQuoteTextInEditor) {
Copy link
Owner

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?

Copy link
Contributor Author

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.

@rafalp
Copy link
Owner

rafalp commented Jun 28, 2023

Did you format the code with prettier? I think those multiline conditions should be wrapped in parenthesis by it ((...)) and I like them that way more.

@manuel12
Copy link
Contributor Author

Did you format the code with prettier? I think those multiline conditions should be wrapped in parenthesis by it ((...)) and I like them that way more.

For me it's removing the parenthesis on save.

@rafalp
Copy link
Owner

rafalp commented Jun 29, 2023

You are correct, I am wrapping those in !!(...) elsewhere in code to prevent it from doing this.

@manuel12
Copy link
Contributor Author

You are correct, I am wrapping those in !!(...) elsewhere in code to prevent it from doing this.

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
Copy link
Owner

@rafalp rafalp Jun 30, 2023

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 = !!(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const editorEmpty = !!(
const formEmpty = !!(

@@ -40,6 +40,17 @@ export default class extends Form {
}

onCancel = () => {
const editorEmpty = !!(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const editorEmpty = !!(
const formEmpty = !!(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rafalp rafalp added area: frontend This issue involves JavaScript, React.js and Node enhancement Improvement to existing feature or dev experience labels Jul 1, 2023
@rafalp
Copy link
Owner

rafalp commented Jul 1, 2023

hljs is no longer minified. Same for zxcvbn.js? 🤔

@manuel12
Copy link
Contributor Author

manuel12 commented Jul 1, 2023

hljs is no longer minified. Same for zxcvbn.js? 🤔

I was running npm run start before to build. Now I've ran npm run build for production and commited it.

@coveralls
Copy link

coveralls commented Jul 1, 2023

Coverage Status

coverage: 98.563% (-0.009%) from 98.572% when pulling 548ad4b on manuel12:no-discarding-message-when-editor-empty into e3b0786 on rafalp:main.

@rafalp
Copy link
Owner

rafalp commented Jul 1, 2023

Please rebase and I'll merge this <3

@manuel12 manuel12 force-pushed the no-discarding-message-when-editor-empty branch from 44f55f8 to 548ad4b Compare July 3, 2023 15:14
@manuel12
Copy link
Contributor Author

manuel12 commented Jul 3, 2023

@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 Push rejected: non fast-forward issue. So I don't know if this works or not.

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.

@manuel12 manuel12 requested a review from rafalp July 3, 2023 15:17
@rafalp
Copy link
Owner

rafalp commented Jul 8, 2023

Trick to rebase is that you pull main branch first to make sure it has latest changes. Then on your branch you do rebase -i main. For every conflict you change your files to fix the conflict, then git add them and do git rebase --continue. If you git commit during rebase you will mess up the git changes tree.

But at the end I'll squash your changes on merge, so those all commits will be rolled up into one on main branch.

@manuel12
Copy link
Contributor Author

Trick to rebase is that you pull main branch first to make sure it has latest changes. Then on your branch you do rebase -i main. For every conflict you change your files to fix the conflict, then git add them and do git rebase --continue. If you git commit during rebase you will mess up the git changes tree.

But at the end I'll squash your changes on merge, so those all commits will be rolled up into one on main branch.

Ok. Should I do anything more on my side or? :)

@rafalp rafalp merged commit d2cd85a into rafalp:main Jul 11, 2023
1 check passed
@rafalp
Copy link
Owner

rafalp commented Jul 11, 2023

Thank you!

@manuel12
Copy link
Contributor Author

Thank you!

Glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: frontend This issue involves JavaScript, React.js and Node enhancement Improvement to existing feature or dev experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't ask user about discarding message/losing changes if they haven't done anything in editor
3 participants