From 229c51def41048a1c06a6d962892d6f8703fad61 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 7 Jan 2021 15:22:51 +0200 Subject: [PATCH] In app release notes (#554) * Remove warning * Add in-app release notes * Update changelog url --- assets/js/app.js | 42 +++++++++++++++++++ .../templates/layout/app.html.eex | 3 ++ 2 files changed, 45 insertions(+) diff --git a/assets/js/app.js b/assets/js/app.js index ea7e58f3c..4232f5968 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -52,3 +52,45 @@ if (registerForm) { plausible('Signup', {callback: submitForm}); }) } + +const changelogNotification = document.getElementById('changelog-notification') + +if (changelogNotification) { + showChangelogNotification(changelogNotification) + + fetch('https://plausible.io/changes.txt', {headers: {'Content-Type': 'text/plain'}}) + .then((res) => res.text()) + .then((res) => { + localStorage.lastChangelogUpdate = new Date(res).getTime() + showChangelogNotification(changelogNotification) + }) +} + +function showChangelogNotification(el) { + const lastUpdated = Number(localStorage.lastChangelogUpdate) + const lastChecked = Number(localStorage.lastChangelogClick) + + if (lastChecked) { + const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked + const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72 + if (hasNewUpdateSinceLastClicked && notOlderThanThreeDays) { + el.innerHTML = ` + + + + + + + + + ` + const link = el.getElementsByTagName('a')[0] + link.addEventListener('click', function() { + localStorage.lastChangelogClick = Date.now() + setTimeout(() => { link.remove() }, 100) + }) + } + } else { + localStorage.lastChangelogClick = Date.now() + } +} diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex index 1ac1acb7c..760b171a3 100644 --- a/lib/plausible_web/templates/layout/app.html.eex +++ b/lib/plausible_web/templates/layout/app.html.eex @@ -50,6 +50,9 @@ + <%= if @conn.assigns[:current_user].email in ["me@markosaric.com", "uku@plausible.io"] do %> +
  • + <% end %> <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_authentication) -> %>