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';
import $ from 'jquery';
import TypoModal from '../Modal/';
import ContextExtractor from './ContextExtractor';
import {i18n} from '../Localization';
import {config} from '../config';
......@@ -18,8 +19,8 @@ class App extends Component {
isTimeout: false,
}
this.selectionContext = "";
this.typo = "";
this.registerHandlers();
}
......@@ -39,7 +40,9 @@ class App extends Component {
return;
}
const contextExtractor = new ContextExtractor();
const selection = this.getSelectedText();
this.selectionContext = contextExtractor.getContextForSelection();
if (selection === "") {
return;
......@@ -68,7 +71,7 @@ class App extends Component {
if (!this.state.correctionMode) return null;
return (
<TypoModal text={this.typo}
<TypoModal text={this.typo} context={this.selectionContext}
closeCallback={this.modalClosedCallback}
show={this.state.correctionMode}/>
);
......@@ -82,9 +85,7 @@ class App extends Component {
});
window.setTimeout(() => {
console.log("state", this.state);
this.setState({ isTimeout: false });
console.log("afterstate", this.state);
}, config.requestTimeout);
}
......
......@@ -3,8 +3,8 @@ import { Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert }
import $ from 'jquery';
import './Modal.css';
import { i18n } from '../Localization';
import { i18n } from '../Localization';
import { config } from '../config';
const alertify = require("alertify.js");
......@@ -18,6 +18,7 @@ class TypoModal extends Component {
show: this.props.show,
text: this.props.text,
correct: this.props.text,
context: this.props.context,
comment: "",
error: ""
}
......@@ -95,7 +96,7 @@ class TypoModal extends Component {
comment: this.state.correct,
// TODO: context
context: "",
context: this.state.context,
// This is a comment for a correction
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