Skip to content

Commit 4e379dc

Browse files
committed
Don't download new page, if already existing under current page
1 parent 11a3e64 commit 4e379dc

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

webApp/src/main/scala/wust/webApp/state/GlobalState.scala

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import wust.api._
1212
import wust.graph._
1313
import wust.ids._
1414
import wust.sdk._
15+
import wust.util.algorithm.dfs
1516
import wust.webApp.jsdom.{ Notifications, ServiceWorker }
1617
import wust.webApp.parsers.{ UrlConfigParser, UrlConfigWriter }
1718
import wust.webApp.views._
@@ -175,7 +176,15 @@ object GlobalState {
175176
val showPageNotFound = Rx { !isLoading() && !pageExistsInGraph() && viewIsContent() }
176177

177178
def focus(nodeId: NodeId, needsGet: Boolean = true) = {
178-
urlConfig.update(_.focus(Page(nodeId), needsGet = needsGet))
179+
val alreadyLoaded = (
180+
for {
181+
pageId <- page.now.parentId
182+
pageIdx <- graph.now.idToIdx(pageId)
183+
nodeIdx <- graph.now.idToIdx(nodeId)
184+
} yield dfs.exists(_(pageIdx), dfs.withStart, graph.now.childrenIdx, isFound = { _ == nodeIdx })
185+
).getOrElse(false)
186+
187+
urlConfig.update(_.focus(Page(nodeId), needsGet = needsGet && !alreadyLoaded))
179188
}
180189

181190
def focusSubPage(nodeIdOpt: Option[NodeId]) = {
@@ -263,21 +272,21 @@ object GlobalState {
263272
focus(nodeId)
264273
graph.now.nodesById(nodeId).foreach { node =>
265274
node.role match {
266-
case NodeRole.Task => FeatureState.use(Feature.ZoomIntoTask)
275+
case NodeRole.Task => FeatureState.use(Feature.ZoomIntoTask)
267276
case NodeRole.Message => FeatureState.use(Feature.ZoomIntoMessage)
268-
case NodeRole.Note => FeatureState.use(Feature.ZoomIntoNote)
269-
case _ =>
277+
case NodeRole.Note => FeatureState.use(Feature.ZoomIntoNote)
278+
case _ =>
270279
}
271280
}
272281
},
273282
)
274283
}
275284

276-
def showOnlyInFullMode(modifier: => VDomModifier, additionalModes:List[PresentationMode] = Nil)(implicit ctx:Ctx.Owner): VDomModifier = {
285+
def showOnlyInFullMode(modifier: => VDomModifier, additionalModes: List[PresentationMode] = Nil)(implicit ctx: Ctx.Owner): VDomModifier = {
277286
GlobalState.presentationMode.map {
278-
case PresentationMode.Full => modifier
287+
case PresentationMode.Full => modifier
279288
case mode if additionalModes contains mode => modifier
280-
case _ => VDomModifier.empty
289+
case _ => VDomModifier.empty
281290
}
282291
}
283292

0 commit comments

Comments
 (0)