From 42619cf3a6ea8c9dc884a28edf6a0868af260ac1 Mon Sep 17 00:00:00 2001 From: updraft0 Date: Wed, 12 Jun 2024 12:13:43 +0100 Subject: [PATCH] chore(ui): reload if version mismatches between frontend and backend --- ui/src/main/css/app.css | 8 ++++++-- ui/src/main/scala/controltower/db/reference.scala | 10 ++++++++++ .../page/map/view/SolarSystemInfoView.scala | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/src/main/css/app.css b/ui/src/main/css/app.css index 203a173..d197e0f 100644 --- a/ui/src/main/css/app.css +++ b/ui/src/main/css/app.css @@ -530,14 +530,18 @@ tr.solar-system-properties > mark { font-size: 0.9em; } -tr.solar-system-properties > mark:first-of-type { +tr.solar-system-properties mark:first-of-type { margin-left: 0; } -tr.solar-system-properties > mark.system-planets { +tr.solar-system-properties mark.system-planets { margin-right: auto; } +tr.solar-system-properties mark.system-class { + width: fit-content; +} + mark.system-planets { color: $gray-lighter; } diff --git a/ui/src/main/scala/controltower/db/reference.scala b/ui/src/main/scala/controltower/db/reference.scala index bc00612..b192393 100644 --- a/ui/src/main/scala/controltower/db/reference.scala +++ b/ui/src/main/scala/controltower/db/reference.scala @@ -4,6 +4,7 @@ import controltower.backend.ControlTowerBackend import org.getshaka.nativeconverter.NativeConverter.given import org.getshaka.nativeconverter.{NativeConverter, fromNative} import org.scalajs.dom.idb.* +import org.updraft0.controltower.build.BuildInfo import org.updraft0.controltower.protocol.* import org.updraft0.controltower.protocol.native.given @@ -31,6 +32,7 @@ object ReferenceDataStore: def usingBackend()(using ct: ControlTowerBackend): Future[ReferenceDataStore] = for version <- ct.getVersion() + _ <- refreshIfVersionMismatch(version) ds <- IdbReferenceDataStore(version.data, version.code) yield ds @@ -252,3 +254,11 @@ private def onFinished(trx: Transaction): Future[Unit] = res.complete(Failure(IndexedDbError("transaction aborted", e))) } res.future + +// arguably the wrong place for this but +private def refreshIfVersionMismatch(version: ReferenceVersion) = + if (version.code != BuildInfo.gitHash) + org.scalajs.dom.console.log(s"Reloading due to server version ${version.code} != ${BuildInfo.gitHash}") + org.scalajs.dom.window.location.reload() + Future.never + else Future.unit diff --git a/ui/src/main/scala/controltower/page/map/view/SolarSystemInfoView.scala b/ui/src/main/scala/controltower/page/map/view/SolarSystemInfoView.scala index 577b30c..d7800c2 100644 --- a/ui/src/main/scala/controltower/page/map/view/SolarSystemInfoView.scala +++ b/ui/src/main/scala/controltower/page/map/view/SolarSystemInfoView.scala @@ -15,7 +15,7 @@ class SolarSystemInfoView(staticData: SystemStaticData, selectedSystem: Observab override def view = div( - idAttr := "solarys-system-info-view", + idAttr := "solar-system-info-view", cls := "solar-system-info-view", cls := "left-sidebar-view", table(children <-- selectedSystem.map {