From 3a8513e59694396dbaada8b9c6603869442589f2 Mon Sep 17 00:00:00 2001 From: tangentstorm Date: Sun, 28 Jan 2024 19:40:09 -0500 Subject: [PATCH] disable/enable buttons based on client state --- tanco/app.py | 2 ++ tanco/static/style.css | 2 +- tanco/templates/attempt.html | 13 ++++++++----- tanco/templates/index.html | 6 ++++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tanco/app.py b/tanco/app.py index d602329..47d97f5 100644 --- a/tanco/app.py +++ b/tanco/app.py @@ -91,8 +91,10 @@ async def notify(code, data, wrap=True): async def notify_client_state(code): data = dict(name="client", status='connected') + data['attrs'] = 'hx-on::load=clientHere()' if not clients.get(code): data['status'] = 'disconnected' + data['attrs'] = 'hx-on::load=clientGone()' html = await quart.render_template_string(''' {% import 'websocket.html' as ws %} diff --git a/tanco/static/style.css b/tanco/static/style.css index c15ad65..8866bf7 100644 --- a/tanco/static/style.css +++ b/tanco/static/style.css @@ -52,7 +52,7 @@ a:hover { color: #0162c2ff; background: #f3f0e5; } #buttons { display: inline-block; } -#shell.hidden { display: none } +.hidden { display: none } #shell { --shell-width: 500px; background: #999; border: solid #333 1px; diff --git a/tanco/templates/attempt.html b/tanco/templates/attempt.html index 156d3ab..14fb74e 100644 --- a/tanco/templates/attempt.html +++ b/tanco/templates/attempt.html @@ -19,10 +19,13 @@ let ws = new WebSocket(url) const el = document.getElementById('browser-ws') el.addEventListener('htmx:wsOpen', e=> { + // can't cache this because element is replaced + document.getElementById('client-ws').classList.remove('hidden'); el.classList.remove('disconnected'); el.classList.add('connected'); el.querySelector('.status').innerHTML='connected'; }); el.addEventListener('htmx:wsClose', e=> { + document.getElementById('client-ws').classList.add('hidden'); el.classList.remove('connected'); el.classList.add('disconnected'); el.querySelector('.status').innerHTML='disconnected'}); @@ -50,21 +53,21 @@

passed tests

{% include "state.html" %}
- - -