[Задача 12799] Добавил progress bar для всех действий над опечатками

parent f0a0e621
...@@ -2,7 +2,7 @@ import React from 'react' ...@@ -2,7 +2,7 @@ import React from 'react'
import {Nav, NavItem, NavLink, TabContent, TabPane, Alert, Badge} from "reactstrap"; import {Nav, NavItem, NavLink, TabContent, TabPane, Alert, Badge} from "reactstrap";
import TypoList from "./TypoList/"; import TypoList from "./TypoList/";
import FaRefresh from 'react-icons/lib/fa/refresh'; import FaRefresh from 'react-icons/lib/fa/refresh';
import TopBarProgress from 'react-topbar-progress-indicator';
export default class SiteList extends React.Component { export default class SiteList extends React.Component {
...@@ -13,28 +13,43 @@ export default class SiteList extends React.Component { ...@@ -13,28 +13,43 @@ export default class SiteList extends React.Component {
this.state = { this.state = {
activeTab: 0, activeTab: 0,
error: false, error: false,
refreshing: true
}; };
this.typos = []; this.typos = [];
this.updateTyposForActiveSite(); // Настройка прогресс бара
} TopBarProgress.config({
barColors: {
"0": "#ffc107",
"1.0": "#ffc107",
}
});
updateTyposForActiveSite = () => { this.updateTab();
this.loadSiteTypos(this.state.activeTab, () =>
this.forceUpdate()
);
} }
toggle = (tab) => { /**
if (this.state.activeTab !== tab) { * Обновляет содержимое данной вкладки или текущей активной вкладки,
/* Обновляем стейт только после загрузки опечаток */ * если параметр не указан. Если указанная вкладка не является активной,
this.loadSiteTypos(tab, () => { * то делает её активной.
this.state.activeTab = tab; *
this.forceUpdate(); * @param tab Если указан, то обновляет содержимое данной вкладки
*/
updateTab = (tab) => {
this.setState({
refreshing: true
});
tab = tab === undefined ? this.state.activeTab : tab;
this.loadSiteTypos(tab, () =>
this.setState({
refreshing: false,
activeTab: tab
}) })
} );
}; }
loadSiteTypos(siteId, done) { loadSiteTypos(siteId, done) {
$.ajax({ $.ajax({
...@@ -59,7 +74,7 @@ export default class SiteList extends React.Component { ...@@ -59,7 +74,7 @@ export default class SiteList extends React.Component {
const tabItems = this.sites.map((site, index) => const tabItems = this.sites.map((site, index) =>
<NavItem key={index}> <NavItem key={index}>
<NavLink className={this.state.activeTab === index ? "active" : ""} <NavLink className={this.state.activeTab === index ? "active" : ""}
onClick={() => { this.toggle(index) }}> onClick={() => { this.updateTab(index) }}>
{site.name} {site.name}
<Badge id={site.id + "-typos-count"} className={"typos-count"} <Badge id={site.id + "-typos-count"} className={"typos-count"}
...@@ -67,9 +82,9 @@ export default class SiteList extends React.Component { ...@@ -67,9 +82,9 @@ export default class SiteList extends React.Component {
{this.typos.length} {this.typos.length}
</Badge> </Badge>
</NavLink> </NavLink>
{this.state.activeTab === index ? {this.state.activeTab === index &&
<FaRefresh className="refresh-site" title="Обновить" onClick={this.updateTyposForActiveSite} /> : <FaRefresh className="refresh-site" title="Обновить"
null} onClick={ () => { this.updateTab() } } />}
</NavItem> </NavItem>
); );
...@@ -107,6 +122,7 @@ export default class SiteList extends React.Component { ...@@ -107,6 +122,7 @@ export default class SiteList extends React.Component {
return ( return (
<div> <div>
{this.state.refreshing && <TopBarProgress />}
<Nav pills fill> <Nav pills fill>
{tabItems} {tabItems}
</Nav> </Nav>
......
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Card, CardHeader, CardBody, CardText} from 'reactstrap' import {Card, CardHeader, CardBody, CardText} from 'reactstrap'
import TopBarProgress from 'react-topbar-progress-indicator';
import Typo from "../Typo/"; import Typo from "../Typo/";
...@@ -13,6 +14,7 @@ const alertify = require("alertify.js"); ...@@ -13,6 +14,7 @@ const alertify = require("alertify.js");
export default class TypoList extends Component { export default class TypoList extends Component {
state = { state = {
loading: false,
siteId: 0, siteId: 0,
resolvedTypos: [] resolvedTypos: []
}; };
...@@ -25,25 +27,29 @@ export default class TypoList extends Component { ...@@ -25,25 +27,29 @@ export default class TypoList extends Component {
* @param corrected Финальный вариант исправления * @param corrected Финальный вариант исправления
*/ */
acceptCorrection(typoId, corrected) { acceptCorrection(typoId, corrected) {
this.setState({
loading: true
});
this._setTypoStatus(1, typoId, this.state.siteId, corrected) this._setTypoStatus(1, typoId, this.state.siteId, corrected)
.done((response) => { .done((response) => {
if (response.error === false) { if (response.error === false) {
alertify.success(`<p>Опечатка ${typoId} была подтверждена.</p> alertify.success(`<p>Опечатка ${typoId} была подтверждена.</p>
<p>Исправления применены к тексту, содержащему опечатку.</p>`); <p>Исправления применены к тексту, содержащему опечатку.</p>`);
this.state.resolvedTypos.push(typoId) this.state.resolvedTypos.push(typoId);
this._decrementSiteTyposCount(); this._decrementSiteTyposCount();
this.forceUpdate(); } else {
return true; alertify.error(response.message);
} }
alertify.error(response.message);
return false;
}) })
.fail(() => { .fail(() => {
alertify.error("Ошибка исправления опечатки, попробуйте позже"); alertify.error("Ошибка исправления опечатки, попробуйте позже");
return false; }).always(() => {
}) this.setState({
loading: false
});
});
} }
/** /**
...@@ -53,19 +59,23 @@ export default class TypoList extends Component { ...@@ -53,19 +59,23 @@ export default class TypoList extends Component {
* @param typoId Идентификатор опечатки. * @param typoId Идентификатор опечатки.
*/ */
declineCorrection(typoId) { declineCorrection(typoId) {
this.setState({
loading: true
});
this._setTypoStatus(0, typoId, this.state.siteId) this._setTypoStatus(0, typoId, this.state.siteId)
.done(() => { .done(() => {
alertify.success(`Опечатка ${typoId} была отклонена`); alertify.success(`Опечатка ${typoId} была отклонена`);
this.state.resolvedTypos.push(typoId); this.state.resolvedTypos.push(typoId);
this._decrementSiteTyposCount(); this._decrementSiteTyposCount();
this.forceUpdate();
return true;
}) })
.fail(() => { .fail(() => {
alertify.error("Ошибка исправления опечатки, попробуйте позже"); alertify.error("Ошибка исправления опечатки, попробуйте позже");
return false; }).always(() => {
this.setState({
loading: false
});
}); });
} }
...@@ -133,6 +143,7 @@ export default class TypoList extends Component { ...@@ -133,6 +143,7 @@ export default class TypoList extends Component {
return ( return (
<div> <div>
{this.state.loading && <TopBarProgress />}
{typoCards} {typoCards}
</div> </div>
) )
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"react": "^16.3.2", "react": "^16.3.2",
"react-dom": "^16.3.0", "react-dom": "^16.3.0",
"react-icons": "^2.2.7", "react-icons": "^2.2.7",
"react-topbar-progress-indicator": "^2.0.0",
"reactstrap": "^5.0.0-beta.3", "reactstrap": "^5.0.0-beta.3",
"whatwg-fetch": "^2.0.4" "whatwg-fetch": "^2.0.4"
}, },
......
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