add progress bar and filters notifications

This commit is contained in:
Ildar Kamalov
2018-09-19 18:58:55 +03:00
parent 0292d2b32b
commit 0e173d2f70
7 changed files with 44 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { createAction } from 'redux-actions';
import round from 'lodash/round';
import { showLoading, hideLoading } from 'react-redux-loading-bar';
import { normalizeHistory, normalizeFilteringStatus, normalizeLogs } from '../helpers/helpers';
import Api from '../api/Api';
@@ -212,13 +213,17 @@ export const toggleLogStatusSuccess = createAction('TOGGLE_LOGS_SUCCESS');
export const toggleLogStatus = queryLogEnabled => async (dispatch) => {
dispatch(toggleLogStatusRequest());
let toggleMethod;
let successMessage;
if (queryLogEnabled) {
toggleMethod = apiClient.disableQueryLog.bind(apiClient);
successMessage = 'disabled';
} else {
toggleMethod = apiClient.enableQueryLog.bind(apiClient);
successMessage = 'enabled';
}
try {
await toggleMethod();
dispatch(addSuccessToast(`Query log ${successMessage}`));
dispatch(toggleLogStatusSuccess());
} catch (error) {
dispatch(addErrorToast({ error }));
@@ -234,6 +239,7 @@ export const setRules = rules => async (dispatch) => {
dispatch(setRulesRequest());
try {
await apiClient.setRules(rules);
dispatch(addSuccessToast('Custom rules saved'));
dispatch(setRulesSuccess());
} catch (error) {
dispatch(addErrorToast({ error }));
@@ -288,13 +294,27 @@ export const refreshFiltersSuccess = createAction('FILTERING_REFRESH_SUCCESS');
export const refreshFilters = () => async (dispatch) => {
dispatch(refreshFiltersRequest);
dispatch(showLoading());
try {
await apiClient.refreshFilters();
const refreshText = await apiClient.refreshFilters();
dispatch(refreshFiltersSuccess);
if (refreshText.includes('OK')) {
if (refreshText.includes('OK 0')) {
dispatch(addSuccessToast('All filters are already up-to-date'));
} else {
dispatch(addSuccessToast(refreshText.replace(/OK /g, '')));
}
} else {
dispatch(addErrorToast({ error: refreshText }));
}
dispatch(getFilteringStatus());
dispatch(hideLoading());
} catch (error) {
dispatch(addErrorToast({ error }));
dispatch(refreshFiltersFailure());
dispatch(hideLoading());
}
};
@@ -378,6 +398,7 @@ export const setUpstream = url => async (dispatch) => {
dispatch(setUpstreamRequest());
try {
await apiClient.setUpstream(url);
dispatch(addSuccessToast('Upstream DNS servers saved'));
dispatch(setUpstreamSuccess());
} catch (error) {
dispatch(addErrorToast({ error }));

View File

@@ -17,3 +17,10 @@ body {
min-height: calc(100vh - 117px);
}
}
.loading-bar {
position: absolute;
z-index: 103;
height: 3px;
background: linear-gradient(45deg, rgba(99, 125, 120, 1) 0%, rgba(88, 177, 101, 1) 100%);
}

View File

@@ -1,6 +1,7 @@
import React, { Component, Fragment } from 'react';
import { HashRouter, Route } from 'react-router-dom';
import PropTypes from 'prop-types';
import LoadingBar from 'react-redux-loading-bar';
import 'react-table/react-table.css';
import '../ui/Tabler.css';
@@ -31,6 +32,7 @@ class App extends Component {
return (
<HashRouter hashType='noslash'>
<Fragment>
<LoadingBar className="loading-bar" updateTime={1000} />
<Route component={Header} />
<div className="container container--wrap">
{!dashboard.processing && !dashboard.isCoreRunning &&

View File

@@ -20,7 +20,7 @@ class Dashboard extends Component {
this.props.getStats();
this.props.getStatsHistory();
this.props.getTopStats();
};
}
render() {
const { dashboard } = this.props;

View File

@@ -1,5 +1,6 @@
import { combineReducers } from 'redux';
import { handleActions } from 'redux-actions';
import { loadingBarReducer } from 'react-redux-loading-bar';
import nanoid from 'nanoid';
import * as actions from '../actions';
@@ -207,4 +208,5 @@ export default combineReducers({
queryLogs,
filtering,
toasts,
loadingBar: loadingBarReducer,
});