From 34a7182877c4672d8068ca1a154f320b4fad6b14 Mon Sep 17 00:00:00 2001 From: Jasneet Singh Date: Sat, 25 Jan 2025 10:00:34 -0500 Subject: [PATCH] Add version tracking and notification for updates in Settings page --- Client/src/Pages/Settings/index.jsx | 41 ++++++++++++++++------------- Client/version.js | 1 + 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 Client/version.js diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index 3cabac713..9bf9b2b87 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -23,6 +23,8 @@ import { settingsValidation } from "../../Validation/validation"; import Dialog from "../../Components/Dialog"; import { useIsAdmin } from "../../Hooks/useIsAdmin"; import ConfigBox from "../../Components/ConfigBox"; +import { version } from "../../../version"; + const SECONDS_PER_DAY = 86400; const Settings = () => { @@ -38,30 +40,33 @@ const Settings = () => { const [form, setForm] = useState({ ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0, }); - const [version, setVersion] = useState("unknown"); const [errors, setErrors] = useState({}); const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false }; const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState); const dispatch = useDispatch(); //Fetching latest release version from github - useEffect(() => { - const fetchLatestVersion = async () => { - let version = "unknown"; - try { - const response = await networkService.fetchGithubLatestRelease(); - if (!response.status === 200) { - throw new Error("Failed to fetch latest version"); - } - version = response.data.tag_name; - } catch (error) { - createToast({ body: error.message || "Error fetching latest version" }); // Set error message - } finally { - setVersion(version); - } - }; - fetchLatestVersion(); - }, []); + useEffect(() => { + const fetchLatestVersion = async () => { + let fetchedVersion = "unknown"; + try { + const response = await networkService.fetchGithubLatestRelease(); + if (!response.status === 200) { + throw new Error("Failed to fetch latest version"); + } + fetchedVersion = response.data.tag_name; + if (fetchedVersion && version !== fetchedVersion) { + createToast({ + body: `A new update is available! Current version: ${version}, New version: ${fetchedVersion}`, + type: "info", + }); + } + } catch (error) { + createToast({ body: error.message || "Error fetching latest version" }); + } + }; + fetchLatestVersion(); + }, []); const handleChange = (event) => { const { value, id } = event.target; diff --git a/Client/version.js b/Client/version.js new file mode 100644 index 000000000..726d9a636 --- /dev/null +++ b/Client/version.js @@ -0,0 +1 @@ +export const version = "v2.0.1"; \ No newline at end of file