A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: improve version and change log logic
thecodrr318948e0af25
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 30689cd36..c5a633103 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -25,7 +25,10 @@ import hashroutes from "./navigation/hash-routes";import rootroutes from "./navigation/rootroutes";import { getCurrentPath } from "./navigation";import useVersion from "./utils/useVersion";-import { showAppUpdatedNotice } from "./components/dialogs/confirm";+import {+ showAppAvailableNotice,+ showAppUpdatedNotice,+} from "./components/dialogs/confirm";function App() {const [show, setShow] = useState(true);@@ -46,6 +49,7 @@ function App() {useEffect(() => {(async function () {if (version.appUpdated) await showAppUpdatedNotice(version);+ else if (version.appUpdateable) await showAppAvailableNotice(version);})();}, [version]);diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.jsindex 253e2fa14..837206f2c 100644--- a/apps/web/src/components/dialogs/confirm.js+++ b/apps/web/src/components/dialogs/confirm.js@@ -28,7 +28,10 @@ function Confirm(props) {);}-export function confirm(icon, { title, subtitle, message, yesText, noText }) {+export function confirm(+ icon,+ { title, subtitle, message, yesText, noText, yesAction }+) {return showDialog((perform) => (<Confirmtitle={title}@@ -38,7 +41,10 @@ export function confirm(icon, { title, subtitle, message, yesText, noText }) {noText={noText}icon={icon}onNo={() => perform(false)}- onYes={() => perform(true)}+ onYes={() => {+ if (yesAction) yesAction();+ perform(true);+ }}/>));}@@ -144,3 +150,30 @@ export function showAppUpdatedNotice(version) {yesText: `Yay!`,});}++export function showAppAvailableNotice(version) {+ return confirm(Icon.Update, {+ title: `New version available`,+ message: (+ <Flex+ flexDirection="column"+ bg="bgSecondary"+ p={1}+ sx={{ borderRadius: "default" }}+ >+ <Text variant="title">v{version.formatted} changelog:</Text>+ <Text+ as="pre"+ fontFamily="monospace"+ variant="body"+ mt={1}+ sx={{ overflow: "auto" }}+ >+ {version.changelog || "No change log."}+ </Text>+ </Flex>+ ),+ yesText: `Update now`,+ yesAction: () => window.location.reload(),+ });+}diff --git a/apps/web/src/index.js b/apps/web/src/index.jsindex a3015c766..57f455952 100644--- a/apps/web/src/index.js+++ b/apps/web/src/index.js@@ -11,7 +11,7 @@ import Modal from "react-modal";import App from "./App";import { MotionConfig, AnimationFeature, GesturesFeature } from "framer-motion";import Splash from "./views/splash";-import { APP_VERSION } from "./utils/useVersion";+import { getAppVersion } from "./utils/useVersion";if (process.env.NODE_ENV === "production") {console.log = () => {};@@ -25,7 +25,7 @@ if (process.env.NODE_ENV === "production") {}return event;},- release: `notesnook-web@${APP_VERSION.formatted}`,+ release: `notesnook-web@${getAppVersion().formatted}`,ignoreErrors: [/ResizeObserver loop limit exceeded/],// We recommend adjusting this value in production, or using tracesSampler// for finer controldiff --git a/apps/web/src/utils/useVersion.js b/apps/web/src/utils/useVersion.jsindex bfd174459..969c6cfb5 100644--- a/apps/web/src/utils/useVersion.js+++ b/apps/web/src/utils/useVersion.js@@ -1,23 +1,27 @@+import { useState } from "react";import { useEffect } from "react";import { db } from "../common";-import { usePersistentState } from "./hooks";-export const APP_VERSION = {+var APP_VERSION = {formatted: format(1100),numerical: 1100,- updateAvailable: false,+ appUpdated: false,+ appUpdateable: false,changelog: undefined,+ fetched: false,};-var versionChecked = false;++var CACHED_VERSION = undefined;+export default () => {- const [version, setVersion] = usePersistentState("app_version", APP_VERSION);+ const [version, setVersion] = useState(APP_VERSION);useEffect(() => {(async function () {- setVersion(await getVersion(version));+ const version = await getVersion();+ setVersion(version);})();- // eslint-disable-next-line react-hooks/exhaustive-deps- }, []);+ }, [setVersion]);return version;};@@ -29,29 +33,36 @@ export default () => {function format(version) {const parts = version.toString().split("");return `${parts[0]}.${parts[1]}.${parts[2]}${- parts[3] !== "0" ? parts[3] : ""+ parts[3] && parts[3] !== "0" ? parts[3] : ""}`;}-export async function getVersion(oldVersion) {+export function getAppVersion() {+ return APP_VERSION;+}++export async function getVersion() {try {+ if (APP_VERSION.fetched) return CACHED_VERSION;+const version = await db.version();- if (!version || versionChecked)- return APP_VERSION.numerical > oldVersion.numerical- ? APP_VERSION- : oldVersion;- versionChecked = true;- return {+ if (!version) return APP_VERSION;++ const changelog = version.web_changelog || version.changelog;+ CACHED_VERSION = {formatted: format(version.web),numerical: version.web,appUpdated:- version.web > oldVersion.numerical &&+ version.web > APP_VERSION.numerical &&APP_VERSION.numerical === version.web,+ appUpdateable: version.web > APP_VERSION.numerical,updateSeverity: version.severity,- changelog: version.changelog === "" ? undefined : version.changelog,+ changelog: !changelog ? undefined : changelog,+ fetched: true,};+ return CACHED_VERSION;} catch (e) {console.error(e);- return oldVersion;}+ return APP_VERSION;}