-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Infinite scroll example errors #2966
Comments
Thanks for pointing this out, @psy0rz! We fixed it by explicitly handling the timeout. |
aweome thanks!! nicegui is the best :) |
well now it works correctly, but on closer inspection: the timer runs on the server and send the javascript code to the client (browser), which in turn return the results. this means that there will be a bunch of websocket messages 10 times per second, even if the user is not scrolling. cant we do better? perhaps some javascript promise that gets resolved only when the user scrolls down enough to trigger additional content? |
Well, you're right. The current implementation might be a proof of concept, but not be very efficient. Here's a rough idea how we could rewrite it using an intersection observer: ui.add_head_html(r'''
<script>
document.addEventListener('DOMContentLoaded', (event) => {
new IntersectionObserver(entries => emitEvent("bottom")).observe(document.querySelector('.footer'));
});
</script>
''')
def load_more():
with images:
for _ in range(10):
ui.image(f'https://picsum.photos/640/360?{time.time()}').classes('w-32')
with ui.column() as images:
load_more()
ui.on('bottom', load_more)
ui.element().classes('footer') I just don't like the initial call to I wonder if there's an easier way to achieve the same result... |
yes i suspected this would be one of those things that can be done, but will get complex very quickly :) for now i'm fine with using a timer of 1 second for my application, but it would be nice if the example would be "perfect" in the future. |
Description
this example works: https://github.com/zauberzeug/nicegui/blob/main/examples/infinite_scroll/main.py
however when you leave the page and goto another you get this:
The text was updated successfully, but these errors were encountered: