Skip to content

Commit

Permalink
Update PrimaryNav.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
goulinkh authored Mar 17, 2023
1 parent 1e105b1 commit 56bc5b0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/components/PrimaryNav/PrimaryNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Icon, StatusLabel, Tooltip } from "@canonical/react-components";
import classNames from "classnames";
import Logo from "components/Logo/Logo";
import UserMenu from "components/UserMenu/UserMenu";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { useSelector } from "react-redux";
import { NavLink } from "react-router-dom";
import { getAppVersion } from "store/general/selectors";
Expand Down Expand Up @@ -70,20 +70,18 @@ const ControllersLink = () => {
);
};

let didInit = false;
const PrimaryNav = () => {
const appVersion = useSelector(getAppVersion);
const [updateAvailable, setUpdateAvailable] = useState(false);
let versionRequested = useRef(false);

useEffect(() => {
if (didInit || !appVersion) return;
didInit = true;
dashboardUpdateAvailable(appVersion || "").then((e) => {
setUpdateAvailable(e);
});
return () => {
didInit = false;
};
if (appVersion && !versionRequested.current) {
dashboardUpdateAvailable(appVersion || "").then((e) => {
setUpdateAvailable(e);
});
versionRequested.current = true;
}
}, [appVersion]);

return (
Expand Down

0 comments on commit 56bc5b0

Please sign in to comment.