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

Smoother loading of the logs page #42

Open
wants to merge 1 commit into
base: test
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
36 changes: 20 additions & 16 deletions paperoni/webapp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,43 @@ def __init__(self, services):
async def run(self, page):
q = Queue()
debounced = ClientWrap(q, debounce=0.3, form=True)
active_service = next(iter(self.services), None)

radio_buttons = [
H.input(
type="radio",
name=f"v-logs-radio",
value=s,
checked=False,
onchange=debounced,
**{"class":"log-button"},
).autoid()
for s in self.services
]
page.print(
H.form["logs-radio"](
*(
H.label["validation-button"](
H.input(
type="radio",
name=f"v-logs-radio",
value=s,
checked=active_service == s,
onchange=debounced,
**{"class":"log-button"},
),
s,
r_b,
r_b.attributes["value"],
)
for s in self.services
for r_b in radio_buttons
)
)
)

page.print(
H.div["log-stream"](
log_stream := H.textarea(
"".join(
self.__class__.journal(active_service, 10000)
if active_service else []
),
"",
name="log-stream",
readonly=True,
).autoid(),
),
)
page[log_stream].do("this.scrollTop = this.scrollTopMax")

for r_b in radio_buttons:
page[r_b].do("this.click()")
break

async for event in q:
for k, v in event.items():
Expand All @@ -129,6 +132,7 @@ async def run(self, page):
page[log_stream].print_html("".join(blocks))
page[log_stream].do("this.scrollTop = this.scrollTopMax")
blocks = ["\n"]
await asyncio.sleep(0.1)
if blocks[1:]:
page[log_stream].print_html("".join(blocks))
page[log_stream].do("this.scrollTop = this.scrollTopMax")
Expand Down