Skip to content

Commit

Permalink
Clear error in between terms and toggling (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiak authored and brendansudol committed Apr 3, 2017
1 parent 14a7a73 commit cdb2340
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/components/Glossary.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class Glossary extends React.Component {
this.applyProps(nextProps)
}

shouldComponentUpdate(nextProps, nextState) {
if (nextState.error) return true
return false
}

setOpen(isOpen) {
if (isOpen) this.glossaryEl.show()
else this.glossaryEl.hide()
Expand All @@ -40,9 +35,10 @@ class Glossary extends React.Component {
showTerm(term) {
if (!term) return

this.setState({ error: null })

try {
this.glossaryEl.findTerm(term.toLowerCase())
this.setState({ error: null })
} catch (e) {
if (e.message === 'Cannot read property \'elm\' of undefined') {
this.setState({ error: `Cannot find "${term}".` })
Expand All @@ -53,7 +49,10 @@ class Glossary extends React.Component {
applyProps(props) {
const { isOpen, term } = props
this.setOpen(isOpen)
if (term) this.showTerm(term)
if (term) {
this.setState({ error: null })
this.showTerm(term)
}
}

toggleGlossary() {
Expand Down

0 comments on commit cdb2340

Please sign in to comment.