Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: isLoading: set true earlier, and false later #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions webApp/src/main/scala/wust/webApp/state/GlobalStateFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import rx.async.Platform._
import scala.concurrent.duration._
import wust.facades.segment.Segment
import wust.api.AuthUser
import scala.concurrent.Future
import scala.util.Success
import scala.util.Failure

object GlobalStateFactory {
def init(): Unit = {
Expand Down Expand Up @@ -140,17 +143,11 @@ object GlobalStateFactory {
}
}

def getNewGraph(page: Page) = {
isLoading() = true
val graph = for {
def getNewGraph(page: Page): Future[Graph] = {
for {
graph <- Client.api.getGraph(page)
} yield enrichVisitedGraphWithSideEffects(page, graph)

graph.transform { result =>
isLoading() = false
result
}
}

// if we have a payment success on startup, the notify user.
urlConfig.now.info.foreach {
Expand All @@ -171,8 +168,15 @@ object GlobalStateFactory {
urlConfig.update(_.copy(invitation = None))

// get a new graph with new right after the accepted invitation
getNewGraph(viewConfig.pageChange.page).foreach { graph =>
eventProcessor.localEvents.onNext(ReplaceGraph(graph))
isLoading() = true
getNewGraph(viewConfig.pageChange.page).onComplete {
case Success(graph) =>
eventProcessor.localEvents.onNext(ReplaceGraph(graph)).foreach { _ =>
isLoading() = false
}
case Failure(_) =>
//TODO: send empty graph event?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when getNewGraph fails, I think we should clear the graph here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//TODO: send empty graph event?
eventProcessor.localEvents.onNext(ReplaceGraph(Graph.empty)).foreach { _ =>
isLoading() = false
}

isLoading() = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isLoading() = false

}
if (wasAssumed) {
Segment.trackEvent("New Unregistered User", js.Dynamic.literal(`type` = "invite"))
Expand Down Expand Up @@ -251,15 +255,25 @@ object GlobalStateFactory {
isFirstGraphRequest = false

result
}.map{ userAndPage =>
isLoading() = true
userAndPage
}.switchMap {
case (viewConfig, user) =>
val currentTransitChanges = lastTransitChanges.fold(GraphChanges.empty)(_ merge _)
SourceStream
.fromFuture(getNewGraph(viewConfig.pageChange.page))
.recover { case _ => Graph.empty }
.recover {
case _ =>
isLoading() = false // TODO: capture error case later, after switchmap did its thing?
Graph.empty
}
.map(g => ReplaceGraph(g.applyChanges(currentTransitChanges)))
}.foreach { graphEvent =>
eventProcessor.localEvents.onNext(graphEvent).foreach { _ =>
isLoading() = false
}
.subscribe(eventProcessor.localEvents)
}
}

GlobalState.permissionState.triggerLater { state =>
Expand Down Expand Up @@ -366,6 +380,7 @@ object GlobalStateFactory {
view.debug("view")
user.debug("auth")
selectedNodes.debug("selected")
isLoading.debug("isLoading")
}
}
}