feat(ui): Add next gen frontend (Work in progress)#2215
Open
herberthobregon wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WORK IN PROGRESS
What
processor, string-built pages, battery-specific HTML snippets).POST /saveSettingsand command endpoints as before, but the UI labels and selects are driven by data from the device (e.g.select_optionson/api/settings) so enums stay in sync with the firmware.Why
Maintainability
Mixing UI markup with C++ made every UI tweak a firmware rebuild and encouraged copy-pasted HTML across battery types. Moving the UI to TypeScript/Lit keeps view code in one place and uses normal web tooling (TypeScript, Vite, linting).
Correct separation of concerns
The device should expose state and actions (JSON, form posts), not presentation (tables, sections, styling). Battery-specific “extra” info is now label/value rows (and optional section titles); the SPA decides how to render them. That scales better as more batteries and screens are added.
Bandwidth and flash
Embedded devices benefit from small payloads. The production bundle is roughly ~60 kB raw and, with gzip, on the order of ~17–20 kB over the wire (exact numbers shift slightly each build). The web server sets
Content-Encoding: gzipso clients download the compressed asset only, which keeps OTA and flash budgets predictable.Future-proofing
A component-based SPA is easier to extend (new routes, mocks for local dev, i18n, accessibility) without touching the real-time C++ paths except to add or extend APIs.
How
Build
Vite bundles
frontend/srcintodist/app.bundle.js(and a tinyindex.htmlshell where applicable). A small script emits C++ sources (app_bundle.cpp/app_bundle.h) that embed the gzipped bytes so the firmware can callrequest->beginResponse(..., data, len)withContent-Encoding: gzip.Serve
The web server registers routes for the SPA entry and
/app.bundle.js(gzip), while authenticated JSON routes power the Lit app. Legacy HTML pages are removed or reduced so there is a single UI story.Data flow
Lit components call
fetch(via a thin API layer) → JSON → reactive@state→ declarativehtmltemplates. Forms that mirror the old POST body field names preserve compatibility with existing NVM handling inwebserver.cpp.Benefits of Lit (LitElement)
Small runtime
Lit keeps a minimal and efficient core, reducing bundle size and improving performance.
Standards-based
Components are real custom elements, compatible with all modern browsers and easy to integrate with vanilla JS or other tools.
Declarative templates
htmltagged templates enable efficient re-rendering and reduce boilerplate compared to manual DOM manipulation.TypeScript-friendly
Strong typing for properties and state, with clear component boundaries, improves safety and readability in large projects.
Scoped styles
static stylesoradoptedStyleSheetsisolate CSS within the component, preventing global style collisions in multi-screen SPAs.Framework-agnostic
Lit is built on native
HTMLElementand does not rely on proprietary syntaxes like JSX or custom DSLs. This ensures that JavaScript written today will remain valid and understandable decades into the future, independent of framework trends.Summary
This architecture trades a bit of upfront tooling for clear boundaries, smaller transfers on the wire, and a UI that can evolve without turning every change into a C++ string-concatenation exercise.