Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the logic in the version check #61

Merged
merged 33 commits into from
Nov 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test version
  • Loading branch information
Ilya-dobri committed Nov 13, 2024
commit 4c34d3ceefc75176ea95b30acc430b8db96f5a44
25 changes: 12 additions & 13 deletions src/views/Layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -91,20 +91,20 @@ const PageLayout: FC<Props> = ({ children }) => {

useEffect(() => {
let intervalId: ReturnType<typeof setInterval> | null = null;

const fetchLatestCommitHash = async () => {
if (!isDomainAllowed()) {
console.warn("Unauthorized domain. Skipping commit hash fetch.");
return;
}

if (!process.env.NEXT_PUBLIC_GITHUB_TOKEN) {
console.warn(
"You have not set the NEXT_PUBLIC_GITHUB_TOKEN environment variable. Skipping commit hash fetch."
);
return;
}

try {
const response = await axios.get(
"https://api.github.com/repos/montelibero-org/stellar-multisig/commits",
@@ -116,33 +116,32 @@ const PageLayout: FC<Props> = ({ children }) => {
);
const latestHash = response.data[0].sha.substring(0, 7);
setCommitHash(latestHash);

if (lastFetchedHash && latestHash !== lastFetchedHash) {
console.log("Version changed. Reloading page...");
window.location.reload(); // Перезагрузка страницы при обнаружении новой версии
console.log("Version changed, reloading page.");
window.location.reload();
}

setLastFetchedHash(latestHash);
} catch (error) {
console.warn("Error fetching commit hash (maybe, your token is wrong):", error);
}
};

const startPolling = () => {
if (intervalId) clearInterval(intervalId);
intervalId = setInterval(
fetchLatestCommitHash,
cacheConfig.checkOfCurrentVersionDurationMs
);
};

const stopPolling = () => {
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
};

const handleVisibilityChange = () => {
if (document.visibilityState === "visible") {
fetchLatestCommitHash();
@@ -151,12 +150,12 @@ const PageLayout: FC<Props> = ({ children }) => {
stopPolling();
}
};

document.addEventListener("visibilitychange", handleVisibilityChange);

fetchLatestCommitHash();
startPolling();

return () => {
stopPolling();
document.removeEventListener("visibilitychange", handleVisibilityChange);