[Задача 12799] Общие исправления. Изменение компонента хранилища состояния опечаток

parent f0577812
...@@ -398,7 +398,7 @@ class Typo extends CI_Model { ...@@ -398,7 +398,7 @@ class Typo extends CI_Model {
try { try {
$client = $this->createConnectionWithAdapter($url); $client = $this->createConnectionWithAdapter($url);
$result = $client->fixTypo($correction->text, $corrected, $correction->context, $correction->link); $result = $client->fixTypo($correction->text, $corrected, $correction->context, $correction->link);
if (!isset($result["errorCode"])) { if (!isset($result["errorCode"])) {
......
...@@ -11,14 +11,15 @@ export default class SiteList extends React.Component { ...@@ -11,14 +11,15 @@ export default class SiteList extends React.Component {
super(props); super(props);
this.sites = this.props.sites; this.sites = this.props.sites;
console.log("Render SiteList");
this.state = { this.state = {
activeTab: 0, activeTab: 0,
error: false, error: false,
refreshing: true refreshing: true,
typos: []
}; };
this.typos = [];
// Настройка прогресс бара // Настройка прогресс бара
TopBarProgress.config({ TopBarProgress.config({
barColors: { barColors: {
...@@ -59,7 +60,9 @@ export default class SiteList extends React.Component { ...@@ -59,7 +60,9 @@ export default class SiteList extends React.Component {
$.ajax({ $.ajax({
url: `${window.baseUrl}/users/typos/getSiteTypos/${this.sites[siteId].id}`, url: `${window.baseUrl}/users/typos/getSiteTypos/${this.sites[siteId].id}`,
}).done((typos) => { }).done((typos) => {
this.typos = typos; this.setState({
typos: typos
});
if (done) { if (done) {
done(); done();
...@@ -74,6 +77,12 @@ export default class SiteList extends React.Component { ...@@ -74,6 +77,12 @@ export default class SiteList extends React.Component {
}); });
} }
removeTypoFromList = (typoId) => {
this.setState({
typos: this.state.typos.filter((typo) => {typo.id !== typoId})
});
}
render() { render() {
const tabItems = this.sites.map((site, index) => const tabItems = this.sites.map((site, index) =>
<NavItem key={index}> <NavItem key={index}>
...@@ -83,7 +92,7 @@ export default class SiteList extends React.Component { ...@@ -83,7 +92,7 @@ export default class SiteList extends React.Component {
<Badge id={site.id + "-typos-count"} className={"typos-count"} <Badge id={site.id + "-typos-count"} className={"typos-count"}
hidden={this.state.activeTab !== index}> hidden={this.state.activeTab !== index}>
{this.typos.length} {this.state.typos.length}
</Badge> </Badge>
</NavLink> </NavLink>
{this.state.activeTab === index && {this.state.activeTab === index &&
...@@ -113,7 +122,7 @@ export default class SiteList extends React.Component { ...@@ -113,7 +122,7 @@ export default class SiteList extends React.Component {
if (this.state.activeTab === index) { if (this.state.activeTab === index) {
return ( return (
<TabPane key={index} tabId={index}> <TabPane key={index} tabId={index}>
<TypoList siteId={site.id} typos={this.typos} /> <TypoList siteId={site.id} typos={this.state.typos} removeTypoCallback={this.removeTypoFromList}/>
</TabPane> </TabPane>
); );
} else { // Если не активная вкладка - то не рендерим содержимое } else { // Если не активная вкладка - то не рендерим содержимое
......
...@@ -112,20 +112,13 @@ export default class Typo extends Component { ...@@ -112,20 +112,13 @@ export default class Typo extends Component {
render() { render() {
const typo = this.typo; const typo = this.typo;
const {show} = this.props;
const display = show ? "d-block" : "d-none"; const display = "d-block";
const textColor = "text-white"; const textColor = "text-white";
const backgroundColor = "bg-primary"; const backgroundColor = "bg-primary";
const className = `TypoCard text-center ${display} ${backgroundColor} ${textColor}`; const className = `TypoCard text-center ${display} ${backgroundColor} ${textColor}`;
if (show) {
console.log("Render typo #" + typo.id);
} else {
return null;
}
if (!this.state.textHighlighted) { if (!this.state.textHighlighted) {
this._highlightTypoInContext(); this._highlightTypoInContext();
this.state.textHighlighted = true; this.state.textHighlighted = true;
......
...@@ -13,11 +13,18 @@ import './style.css' ...@@ -13,11 +13,18 @@ import './style.css'
const alertify = require("alertify.js"); const alertify = require("alertify.js");
export default class TypoList extends Component { export default class TypoList extends Component {
state = { constructor(props) {
loading: false, super(props);
siteId: 0,
resolvedTypos: [] this.state = {
}; loading: false,
siteId: this.props.siteId,
};
this.removeTypo = this.props.removeTypoCallback.bind(this);
console.log("Construct(TypoList):", this);
}
/** /**
* Одобряет исправление опечатки * Одобряет исправление опечатки
...@@ -37,8 +44,7 @@ export default class TypoList extends Component { ...@@ -37,8 +44,7 @@ export default class TypoList extends Component {
alertify.success(`<p>Опечатка ${typoId} была подтверждена.</p> alertify.success(`<p>Опечатка ${typoId} была подтверждена.</p>
<p>Исправления применены к тексту, содержащему опечатку.</p>`); <p>Исправления применены к тексту, содержащему опечатку.</p>`);
this.state.resolvedTypos.push(typoId); this.removeTypo(typoId);
this._decrementSiteTyposCount();
} else { } else {
alertify.error(response.message); alertify.error(response.message);
} }
...@@ -66,9 +72,7 @@ export default class TypoList extends Component { ...@@ -66,9 +72,7 @@ export default class TypoList extends Component {
this._setTypoStatus(0, typoId, this.state.siteId) this._setTypoStatus(0, typoId, this.state.siteId)
.done(() => { .done(() => {
alertify.success(`Опечатка ${typoId} была отклонена`); alertify.success(`Опечатка ${typoId} была отклонена`);
this.removeTypo(typoId);
this.state.resolvedTypos.push(typoId);
this._decrementSiteTyposCount();
}) })
.fail(() => { .fail(() => {
alertify.error("Ошибка исправления опечатки, попробуйте позже"); alertify.error("Ошибка исправления опечатки, попробуйте позже");
...@@ -121,20 +125,18 @@ export default class TypoList extends Component { ...@@ -121,20 +125,18 @@ export default class TypoList extends Component {
} }
render() { render() {
console.log("Render typolist for site " + this.state.siteId);
const {typos} = this.props; this.updateSiteTyposCount();
this.state.siteId = this.props.siteId;
console.log("Render typolist for site " + this.state.siteId); const typos = this.props.typos;
if (typos.length === 0 || this.state.resolvedTypos.length >= typos.length) { if (typos.length === 0) {
return TypoList._displayEmptyMessage(); return TypoList._displayEmptyMessage();
} }
const typoCards = typos.map((typo, index) => const typoCards = typos.map((typo, index) =>
<Typo key={typo.id} typo={typo} <Typo key={typo.id} typo={typo}
show={!this.state.resolvedTypos.includes(typo.id)}
acceptCallback={this.acceptCorrection.bind(this, typo.id)} acceptCallback={this.acceptCorrection.bind(this, typo.id)}
declineCallback={this.declineCorrection.bind(this, typo.id)}/> declineCallback={this.declineCorrection.bind(this, typo.id)}/>
); );
...@@ -153,8 +155,7 @@ export default class TypoList extends Component { ...@@ -153,8 +155,7 @@ export default class TypoList extends Component {
* Уменьшает счетчик опечаток сайта * Уменьшает счетчик опечаток сайта
* @private * @private
*/ */
_decrementSiteTyposCount() { updateSiteTyposCount() {
const value = parseInt($(`#${this.state.siteId}-typos-count`).text()); $(`#${this.state.siteId}-typos-count`).text(this.props.typos.length);
$(`#${this.state.siteId}-typos-count`).text(value-1);
} }
} }
\ No newline at end of file
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