Add context extracting class

parent a1b515f9
// Class that is used to extract context of some word
export default class ContextExtractor {
constructor() {
}
// Returns a context for a current selection
getContextForSelection() {
const text = window.getSelection()
.baseNode.parentNode.textContent
.replace(/\n/g,"")
.replace(/(\s)+/g, " ");
return text;
}
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ import React, { Component } from 'react'; ...@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import $ from 'jquery'; import $ from 'jquery';
import TypoModal from '../Modal/'; import TypoModal from '../Modal/';
import ContextExtractor from './ContextExtractor';
import {i18n} from '../Localization'; import {i18n} from '../Localization';
import {config} from '../config'; import {config} from '../config';
...@@ -18,8 +19,8 @@ class App extends Component { ...@@ -18,8 +19,8 @@ class App extends Component {
isTimeout: false, isTimeout: false,
} }
this.selectionContext = "";
this.typo = ""; this.typo = "";
this.registerHandlers(); this.registerHandlers();
} }
...@@ -39,7 +40,9 @@ class App extends Component { ...@@ -39,7 +40,9 @@ class App extends Component {
return; return;
} }
const contextExtractor = new ContextExtractor();
const selection = this.getSelectedText(); const selection = this.getSelectedText();
this.selectionContext = contextExtractor.getContextForSelection();
if (selection === "") { if (selection === "") {
return; return;
...@@ -68,7 +71,7 @@ class App extends Component { ...@@ -68,7 +71,7 @@ class App extends Component {
if (!this.state.correctionMode) return null; if (!this.state.correctionMode) return null;
return ( return (
<TypoModal text={this.typo} <TypoModal text={this.typo} context={this.selectionContext}
closeCallback={this.modalClosedCallback} closeCallback={this.modalClosedCallback}
show={this.state.correctionMode}/> show={this.state.correctionMode}/>
); );
...@@ -82,9 +85,7 @@ class App extends Component { ...@@ -82,9 +85,7 @@ class App extends Component {
}); });
window.setTimeout(() => { window.setTimeout(() => {
console.log("state", this.state);
this.setState({ isTimeout: false }); this.setState({ isTimeout: false });
console.log("afterstate", this.state);
}, config.requestTimeout); }, config.requestTimeout);
} }
......
...@@ -3,8 +3,8 @@ import { Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert } ...@@ -3,8 +3,8 @@ import { Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert }
import $ from 'jquery'; import $ from 'jquery';
import './Modal.css'; import './Modal.css';
import { i18n } from '../Localization';
import { i18n } from '../Localization';
import { config } from '../config'; import { config } from '../config';
const alertify = require("alertify.js"); const alertify = require("alertify.js");
...@@ -18,6 +18,7 @@ class TypoModal extends Component { ...@@ -18,6 +18,7 @@ class TypoModal extends Component {
show: this.props.show, show: this.props.show,
text: this.props.text, text: this.props.text,
correct: this.props.text, correct: this.props.text,
context: this.props.context,
comment: "", comment: "",
error: "" error: ""
} }
...@@ -95,7 +96,7 @@ class TypoModal extends Component { ...@@ -95,7 +96,7 @@ class TypoModal extends Component {
comment: this.state.correct, comment: this.state.correct,
// TODO: context // TODO: context
context: "", context: this.state.context,
// This is a comment for a correction // This is a comment for a correction
note: this.state.comment, note: this.state.comment,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment