Skip to content

Commit

Permalink
chore(ui): reload if version mismatches between frontend and backend
Browse files Browse the repository at this point in the history
  • Loading branch information
updraft0 committed Jun 12, 2024
1 parent ac0d80c commit 42619cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ui/src/main/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions ui/src/main/scala/controltower/db/reference.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 42619cf

Please sign in to comment.