Skip to content
Open
Show file tree
Hide file tree
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
42 changes: 25 additions & 17 deletions webApp/src/main/scala/views/ChatView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,33 @@ object ChatView {
width := "100%"
),
div(
Styles.flex,
flexDirection.column,
flexDirection.columnReverse, // on resize, align scrolling to bottom (https://stackoverflow.com/questions/34779723/how-to-change-a-scrolling-element-behavior-on-resize-html-css-javascript/34790448#34790448)
cls := "chat-history",
InfiniteScroll.onInfiniteScrollUp(shouldLoadInfinite) --> pageCounter,
backgroundColor <-- state.pageStyle.map(_.bgLightColor),
Rx {
state.page().parentId map { pageParentId =>
VDomModifier(
chatHistory(state, pageParentId, currentReply, selectedNodes, inputFieldFocusTrigger, pageCounter, shouldLoadInfinite),
outerDragOptions(pageParentId)
)
flexGrow := 1,
div(
flexGrow := 1,
backgroundColor <-- state.pageStyle.map(_.bgLightColor),
Rx {
state.page().parentId map { pageParentId =>
VDomModifier(
chatHistory(state, pageParentId, currentReply, selectedNodes, inputFieldFocusTrigger, pageCounter, shouldLoadInfinite),
outerDragOptions(pageParentId)
)
}
},

// clicking on background deselects
onClick foreach { e => if(e.currentTarget == e.target) selectedNodes() = Set.empty[SelectedNode] },
scrollHandler.modifier,
// on page change, always scroll down
emitterRx(state.page).foreach {
scrollHandler.scrollToBottomInAnimationFrame()
}
},

// clicking on background deselects
onClick foreach { e => if(e.currentTarget == e.target) selectedNodes() = Set.empty[SelectedNode] },
scrollHandler.modifier,
// on page change, always scroll down
emitterRx(state.page).foreach {
scrollHandler.scrollToBottomInAnimationFrame()
}
),
// since flexDirection is reversed, InfiniteScroll is written at the bottom instead of top
InfiniteScroll.onInfiniteScrollUp(shouldLoadInfinite) --> pageCounter,
),
emitterRx(state.page).foreach { currentReply() = Set.empty[NodeId] },
onGlobalEscape(Set.empty[NodeId]) --> currentReply,
Expand Down
8 changes: 7 additions & 1 deletion webApp/src/main/scala/views/Elements.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Elements {
def scrollToBottom(elem: dom.Element): Unit = {
//TODO: scrollHeight is not yet available in jsdom tests: https://github.com/tmpvar/jsdom/issues/1013
try {
elem.scrollTop = elem.scrollHeight - elem.clientHeight
elem.scrollTop = elem.scrollHeight
} catch { case _: Throwable => } // with NonFatal(_) it fails in the tests
}

Expand All @@ -52,6 +52,12 @@ object Elements {
} // at bottom + 10 px tolerance

def modifier(implicit ctx: Ctx.Owner) = VDomModifier(
managed(IO(
outwatch.dom.dsl.events.window.onResize.foreach { _ =>
if(isScrolledToBottom.now)
scrollToBottomInAnimationFrame()
}
)),
onDomPreUpdate foreach {
isScrolledToBottom() = isScrolledToBottomNow
},
Expand Down
2 changes: 1 addition & 1 deletion webApp/src/main/scala/views/InfiniteScroll.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object InfiniteScroll {
var numSteps = 0

VDomModifier(
overflow.auto,
overflowY.auto,
shouldLoad.map {
case true => VDomModifier(
div(
Expand Down
30 changes: 19 additions & 11 deletions webApp/src/main/scala/views/ThreadView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,27 @@ object ThreadView {
width := "100%"
),
div(
Styles.flex,
flexDirection.column,
flexDirection.columnReverse, // on resize, align scrolling to bottom (https://stackoverflow.com/questions/34779723/how-to-change-a-scrolling-element-behavior-on-resize-html-css-javascript/34790448#34790448)
cls := "chat-history",
flexGrow := 1,
div(
flexGrow := 1,
backgroundColor <-- state.pageStyle.map(_.bgLightColor),
chatHistory(state, selectedNodes, pageCounter, shouldLoadInfinite),
outerDragOptions,

// clicking on background deselects
onClick foreach { e => if(e.currentTarget == e.target) selectedNodes() = Set.empty[SelectedNode] },
scrollHandler.modifier,
// on page change, always scroll down
emitterRx(state.page).foreach {
scrollHandler.scrollToBottomInAnimationFrame()
}
),
// since flexDirection is reversed, InfiniteScroll is written at the bottom instead of top
InfiniteScroll.onInfiniteScrollUp(shouldLoadInfinite) --> pageCounter,
backgroundColor <-- state.pageStyle.map(_.bgLightColor),
chatHistory(state, selectedNodes, pageCounter, shouldLoadInfinite),
outerDragOptions,

// clicking on background deselects
onClick foreach { e => if(e.currentTarget == e.target) selectedNodes() = Set.empty[SelectedNode] },
scrollHandler.modifier,
// on page change, always scroll down
emitterRx(state.page).foreach {
scrollHandler.scrollToBottomInAnimationFrame()
}
),
{
def submitAction(str:String) = {
Expand Down