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

[Beta: CodeMirror] User can undo past the current challenge #16960

Closed
ghost opened this issue Mar 25, 2018 · 6 comments
Closed

[Beta: CodeMirror] User can undo past the current challenge #16960

ghost opened this issue Mar 25, 2018 · 6 comments
Labels
help wanted Open for all. You do not need permission to work on these. platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: UI Threads for addressing UX changes and improvements to user interface

Comments

@ghost
Copy link

ghost commented Mar 25, 2018

Challenge Name

Any challenge with a code editor.

Issue Description

Steps to reproduce:

  1. Complete a challenge.
  2. Enter some code in the new challenge.
  3. Keep undoing typing and your current code will be reverted to that of the previous challenge.

Browser Information

  • Browser Name, Version: Chrome 65.0.3325.181
  • Operating System: macOS 10.13.3
  • Mobile, Desktop, or Tablet: desktop

Screenshot

freecodecamp beta - undo issue

@raisedadead raisedadead added help wanted Open for all. You do not need permission to work on these. scope: UI Threads for addressing UX changes and improvements to user interface platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. labels Mar 26, 2018
@love1024
Copy link
Contributor

love1024 commented Apr 2, 2018

@raisedadead we need to call clearHistory of codemirror to get rid of undo history when new challenge comes. But when we know that this is new challenge so that we can clear history in Editor.jsx? componentWillMount and componentWillUpdate does not seem right for this. Any Suggestion?

@raisedadead
Copy link
Member

You should be able to hook it to an action in the editor, when a new challenge arrives. /cc @Bouncey can you guide.

@love1024
Copy link
Contributor

love1024 commented Apr 2, 2018

Yes i am getting id of challenge to compare if this challenge is new in componentWillUpdate and then clearing history. This is working fine expect for the first time. Working on this.

@love1024
Copy link
Contributor

love1024 commented Apr 2, 2018

@raisedadead @Bouncey There are two ways to do this
First is to add setTimeout to clear codemirror history

  componentDidUpdate(nextProps) {
    if (nextProps.id !== this.props.id) {
      setTimeout(() => {
        this.refs.editor.getCodeMirror().doc.clearHistory();
      }, 0);
    }
  }

Settimeout is required because codemirror does not give updated value when new challenge is selected as of this issue JedWatson/react-codemirror#106
Second is to use the workaround given in issue to add key to codemirror component to get updated value.I used id of the challenge for this

<codemirror
key = {id}
...
/>

 componentDidUpdate(nextProps) {
    if (nextProps.id !== this.props.id) {
        this.refs.editor.getCodeMirror().doc.clearHistory();
    }
  }

So Any Suggestion which one to use?

@raisedadead
Copy link
Member

I would want to move away to using https://github.com/scniro/react-codemirror2 however, in case its not trivial at the moment I would prefer your second solution.

@love1024
Copy link
Contributor

love1024 commented Apr 2, 2018

yes codemirror2 seems a right option, for now i am raising PR with second solution.

love1024 pushed a commit to love1024/freeCodeCamp that referenced this issue Apr 11, 2018
clear codemirror undo stack on new challenge

Closes freeCodeCamp#16960

fix(editor): Removed not required code

Closes freeCodeCamp#16960

feat(editor): Updated code with coding style

Closes freeCodeCamp#16960
Bouncey pushed a commit that referenced this issue Apr 18, 2018
clear codemirror undo stack on new challenge

Closes #16960

fix(editor): Removed not required code

Closes #16960

feat(editor): Updated code with coding style

Closes #16960
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Open for all. You do not need permission to work on these. platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: UI Threads for addressing UX changes and improvements to user interface
Projects
None yet
Development

No branches or pull requests

3 participants