Skip to content

Commit

Permalink
Do not trigger ScrollButton event unless clicked (#6938)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jul 10, 2024
1 parent 371573d commit 84d379b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion panel/layout/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _process_event(self, event: ScrollButtonClick) -> None:
n_visible = self.visible_range[-1] - self.visible_range[0]
with edit_readonly(self):
# plus one to center on the last object
self.visible_range = (max(n - n_visible + 1, 0), n)
self.visible_range = (min(max(n - n_visible + 1, 0), n), n)

with param.discard_events(self):
# reset the buffers and loaded objects
Expand Down
19 changes: 16 additions & 3 deletions panel/models/column.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {Column as BkColumn, ColumnView as BkColumnView} from "@bokehjs/models/layouts/column"
import * as DOM from "@bokehjs/core/dom"
import {ModelEvent} from "@bokehjs/core/bokeh_events"
import {div} from "@bokehjs/core/dom"
import type * as p from "@bokehjs/core/properties"
import type {EventCallback} from "@bokehjs/model"
import {Column as BkColumn, ColumnView as BkColumnView} from "@bokehjs/models/layouts/column"

export class ScrollButtonClick extends ModelEvent {
static {
this.prototype.event_name = "scroll_button_click"
}
}

export class ColumnView extends BkColumnView {
declare model: Column
Expand Down Expand Up @@ -62,14 +70,15 @@ export class ColumnView extends BkColumnView {

override render(): void {
super.render()
this.scroll_down_button_el = DOM.createElement("div", {class: "scroll-button"})
this.scroll_down_button_el = div({class: "scroll-button"})
this.shadow_el.appendChild(this.scroll_down_button_el)
this.el.addEventListener("scroll", () => {
this.record_scroll_position()
this.toggle_scroll_button()
})
this.scroll_down_button_el.addEventListener("click", () => {
this.scroll_to_latest()
this.model.trigger_event(new ScrollButtonClick())
})
}

Expand Down Expand Up @@ -118,4 +127,8 @@ export class Column extends BkColumn {
view_latest: [Bool, false],
}))
}

on_click(callback: EventCallback<ScrollButtonClick>): void {
this.on_event(ScrollButtonClick, callback)
}
}
22 changes: 1 addition & 21 deletions panel/models/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import {Column, ColumnView} from "./column"
import type * as p from "@bokehjs/core/properties"
import {build_views} from "@bokehjs/core/build_views"
import type {UIElementView} from "@bokehjs/models/ui/ui_element"
import {ModelEvent} from "@bokehjs/core/bokeh_events"
import type {EventCallback} from "@bokehjs/model"

export class ScrollButtonClick extends ModelEvent {
static {
this.prototype.event_name = "scroll_button_click"
}
}

export class FeedView extends ColumnView {
declare model: Feed
Expand Down Expand Up @@ -89,21 +81,13 @@ export class FeedView extends ColumnView {
return created
}

override scroll_to_latest(emit_event: boolean = true): void {
if (emit_event) {
this.model.trigger_event(new ScrollButtonClick())
}
super.scroll_to_latest()
}

override trigger_auto_scroll(): void {
const limit = this.model.auto_scroll_limit
const within_limit = this.distance_from_latest <= limit
if (limit == 0 || !within_limit) {
return
}

this.scroll_to_latest(false)
this.scroll_to_latest()
}
}

Expand Down Expand Up @@ -132,8 +116,4 @@ export class Feed extends Column {
visible_children: [List(Str), []],
}))
}

on_click(callback: EventCallback<ScrollButtonClick>): void {
this.on_event(ScrollButtonClick, callback)
}
}

0 comments on commit 84d379b

Please sign in to comment.