Updates #1577
Squashed commit of the following:
commit a07ff51fb3f1eb58ab9a922d7bc11ed1d65ef3a7
Merge: 7db696814 2f515e8d8
Author: Ildar Kamalov <ik@adguard.com>
Date: Fri Jun 23 16:50:09 2023 +0300
Merge branch 'master' into AG-22207
commit 7db696814f2134fd3a3415cbcfa0ffdac1fabda3
Author: Ildar Kamalov <ik@adguard.com>
Date: Fri Jun 23 14:57:09 2023 +0300
fix changelog
commit bf9458b3f18697ca1fc504c51fa443934f76371f
Author: Ildar Kamalov <ik@adguard.com>
Date: Fri Jun 23 14:48:20 2023 +0300
changelog
commit bc2bf3f9507957afe63a654334b6e22858d1e41b
Author: Ildar Kamalov <ik@adguard.com>
Date: Fri Jun 23 13:28:28 2023 +0300
client: handle rewrite edit
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import { useEffect } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { ONE_SECOND_IN_MS } from '../../helpers/constants';
|
|
import { setProtectionTimerTime, toggleProtectionSuccess } from '../../actions';
|
|
|
|
let interval = null;
|
|
|
|
const ProtectionTimer = ({
|
|
protectionDisabledDuration,
|
|
toggleProtectionSuccess,
|
|
setProtectionTimerTime,
|
|
}) => {
|
|
useEffect(() => {
|
|
if (protectionDisabledDuration !== null && protectionDisabledDuration < ONE_SECOND_IN_MS) {
|
|
toggleProtectionSuccess({ disabledDuration: null });
|
|
}
|
|
|
|
if (protectionDisabledDuration) {
|
|
interval = setInterval(() => {
|
|
setProtectionTimerTime(protectionDisabledDuration - ONE_SECOND_IN_MS);
|
|
}, ONE_SECOND_IN_MS);
|
|
}
|
|
|
|
return () => {
|
|
clearInterval(interval);
|
|
};
|
|
}, [protectionDisabledDuration]);
|
|
|
|
return null;
|
|
};
|
|
|
|
ProtectionTimer.propTypes = {
|
|
protectionDisabledDuration: PropTypes.number,
|
|
toggleProtectionSuccess: PropTypes.func.isRequired,
|
|
setProtectionTimerTime: PropTypes.func.isRequired,
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
const { dashboard } = state;
|
|
const { protectionEnabled, protectionDisabledDuration } = dashboard;
|
|
return { protectionEnabled, protectionDisabledDuration };
|
|
};
|
|
|
|
const mapDispatchToProps = {
|
|
toggleProtectionSuccess,
|
|
setProtectionTimerTime,
|
|
};
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps,
|
|
)(ProtectionTimer);
|