UI: Compare version numbers in VersionComponent

This commit is contained in:
Ilija Lazoroski 2022-08-03 23:48:49 +02:00
parent f13d55d89a
commit ae468f9832
1 changed files with 14 additions and 6 deletions

View File

@ -7,8 +7,8 @@ class VersionComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
currentVersion: undefined,
newerVersion: undefined,
versionNumber: undefined,
latestVersion: undefined,
downloadLink: undefined
}
}
@ -18,19 +18,27 @@ class VersionComponent extends React.Component {
.then(res => res.json())
.then(res => {
this.setState({
currentVersion: res['current_version'],
newerVersion: res['newer_version'],
versionNumber: res['version_number'],
latestVersion: res['latest_version'],
downloadLink: res['download_link']
});
});
}
newerVersionAvailable() {
const semverGt = require('semver/functions/gt');
if(this.state.latestVersion !== undefined && this.state.versionNumber !== undefined) {
return semverGt(this.state.latestVersion, this.state.versionNumber);
}
return false;
}
render() {
return (
<div className="version-text text-center">
Infection Monkey Version: {this.state.currentVersion}
Infection Monkey Version: {this.state.versionNumber}
{
this.state.newerVersion ?
this.newerVersionAvailable() ?
<div>
<b>Newer version available!</b>
<br/>