diff --git a/gulpfile.js b/gulpfile.js index 2945a79f9..98e34bc6f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -127,6 +127,7 @@ const refactoredSrc = [ "./src/js/elements/sign-out-button.js", "./src/js/elements/about-page.js", "./src/js/elements/psa.js", + "./src/js/elements/new-version-notification.js", "./src/js/popups/custom-text-popup.js", "./src/js/popups/quote-search-popup.js", diff --git a/src/js/elements/new-version-notification.js b/src/js/elements/new-version-notification.js new file mode 100644 index 000000000..a24ee5ecd --- /dev/null +++ b/src/js/elements/new-version-notification.js @@ -0,0 +1,30 @@ +import * as Notifications from "./notifications"; +import * as VersionPopup from "./version-popup"; + +export async function show(version) { + const memory = await getMemory(); + if (memory === "") { + setMemory(version); + return; + } + if (memory === version) return; + Notifications.add( + `Version ${version} has been released. Click to view the changelog.`, + 1, + 7, + "Announcement", + "code-branch", + () => { + VersionPopup.show(); + } + ); + setMemory(version); +} + +function setMemory(v) { + window.localStorage.setItem("lastSeenVersion", v); +} + +function getMemory() { + return window.localStorage.getItem("lastSeenVersion") ?? ""; +} diff --git a/src/js/misc.js b/src/js/misc.js index defee7eff..4859d92e5 100644 --- a/src/js/misc.js +++ b/src/js/misc.js @@ -384,8 +384,8 @@ export function median(arr) { } } -export function getReleasesFromGitHub() { - $.getJSON( +export async function getReleasesFromGitHub() { + return $.getJSON( "https://api.github.com/repos/Miodec/monkeytype/releases", (data) => { $("#bottom .version .text").text(data[0].name); diff --git a/src/js/popups/version-popup.js b/src/js/popups/version-popup.js index 9508d103d..62ab426d1 100644 --- a/src/js/popups/version-popup.js +++ b/src/js/popups/version-popup.js @@ -1,8 +1,12 @@ -$(document.body).on("click", ".version", () => { +export function show() { $("#versionHistoryWrapper") .css("opacity", 0) .removeClass("hidden") .animate({ opacity: 1 }, 125); +} + +$(document.body).on("click", ".version", () => { + show(); }); $(document.body).on("click", "#versionHistoryWrapper", () => { diff --git a/src/js/ready.js b/src/js/ready.js index 415a35a40..7ab06212b 100644 --- a/src/js/ready.js +++ b/src/js/ready.js @@ -7,11 +7,14 @@ import * as RouteController from "./route-controller"; import * as UI from "./ui"; import * as SignOutButton from "./sign-out-button"; import * as MonkeyPower from "./monkey-power"; +import * as NewVersionNotification from "./new-version-notification"; ManualRestart.set(); Misc.migrateFromCookies(); UpdateConfig.loadFromLocalStorage(); -Misc.getReleasesFromGitHub(); +Misc.getReleasesFromGitHub().then((v) => { + NewVersionNotification.show(v[0].name); +}); RouteController.handleInitialPageClasses(window.location.pathname); $(document).ready(() => {