From 59a635f3f23bfcca583960f8ebb910d35f13e34d Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Tue, 17 Sep 2019 17:37:26 +0300 Subject: [PATCH] + client: add isVersionGreater helper --- client/src/actions/index.js | 5 ++--- client/src/helpers/helpers.js | 5 +++++ client/src/reducers/index.js | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 351b8221..3087c47d 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -2,8 +2,7 @@ import { createAction } from 'redux-actions'; import { t } from 'i18next'; import axios from 'axios'; -import versionCompare from '../helpers/versionCompare'; -import { normalizeTextarea, sortClients } from '../helpers/helpers'; +import { normalizeTextarea, sortClients, isVersionGreater } from '../helpers/helpers'; import { SETTINGS_NAMES, CHECK_TIMEOUT } from '../helpers/constants'; import { getTlsStatus } from './encryption'; import apiClient from '../api/Api'; @@ -125,7 +124,7 @@ export const getVersion = (recheck = false) => async (dispatch, getState) => { const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; - if (data && versionCompare(currentVersion, data.new_version) === -1) { + if (data && isVersionGreater(currentVersion, data.new_version)) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index 7f2ab78d..2c70d709 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -7,6 +7,7 @@ import subDays from 'date-fns/sub_days'; import round from 'lodash/round'; import axios from 'axios'; import i18n from 'i18next'; +import versionCompare from './versionCompare'; import { STANDARD_DNS_PORT, @@ -279,3 +280,7 @@ export const secondsToMilliseconds = (seconds) => { }; export const normalizeRulesTextarea = text => text && text.replace(/^\n/g, '').replace(/\n\s*\n/g, '\n'); + +export const isVersionGreater = (currentVersion, previousVersion) => ( + versionCompare(currentVersion, previousVersion) === -1 +); diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 568af3ba..00a19816 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -2,7 +2,7 @@ import { combineReducers } from 'redux'; import { handleActions } from 'redux-actions'; import { loadingBarReducer } from 'react-redux-loading-bar'; import { reducer as formReducer } from 'redux-form'; -import versionCompare from '../helpers/versionCompare'; +import { isVersionGreater } from '../helpers/helpers'; import * as actions from '../actions'; import toasts from './toasts'; @@ -108,7 +108,7 @@ const dashboard = handleActions( [actions.getVersionSuccess]: (state, { payload }) => { const currentVersion = state.dnsVersion === 'undefined' ? 0 : state.dnsVersion; - if (payload && versionCompare(currentVersion, payload.new_version) === -1) { + if (payload && isVersionGreater(currentVersion, payload.new_version)) { const { announcement_url: announcementUrl, new_version: newVersion,