| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| 2 | import { customElement, property } from "lit/decorators.js"; |
| 3 | import { DataManager, ConnectionStatus } from "../data"; |
| 4 | import { State, TimelineMessage } from "../types"; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 5 | import { SketchContainerStatus } from "./sketch-container-status"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 6 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 7 | @customElement("sketch-network-status") |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 8 | export class SketchNetworkStatus extends LitElement { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 9 | @property() |
| 10 | connection: string; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 11 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 12 | @property() |
| 13 | message: string; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 14 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 15 | @property() |
| 16 | error: string; |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 17 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 18 | // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS. |
| 19 | // Note that these styles only apply to the scope of this web component's |
| 20 | // shadow DOM node, so they won't leak out or collide with CSS declared in |
| 21 | // other components or the containing web page (...unless you want it to do that). |
| 22 | |
| 23 | static styles = css` |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 24 | .status-container { |
| 25 | display: flex; |
| 26 | align-items: center; |
| 27 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 28 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 29 | .polling-indicator { |
| 30 | display: inline-block; |
| 31 | width: 8px; |
| 32 | height: 8px; |
| 33 | border-radius: 50%; |
| 34 | margin-right: 4px; |
| 35 | background-color: #ccc; |
| 36 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 37 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 38 | .polling-indicator.active { |
| 39 | background-color: #4caf50; |
| 40 | animation: pulse 1.5s infinite; |
| 41 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 42 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 43 | .polling-indicator.error { |
| 44 | background-color: #f44336; |
| 45 | animation: pulse 1.5s infinite; |
| 46 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 47 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 48 | @keyframes pulse { |
| 49 | 0% { |
| 50 | opacity: 1; |
| 51 | } |
| 52 | 50% { |
| 53 | opacity: 0.5; |
| 54 | } |
| 55 | 100% { |
| 56 | opacity: 1; |
| 57 | } |
| 58 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 59 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 60 | .status-text { |
| 61 | font-size: 11px; |
| 62 | color: #666; |
| 63 | } |
| 64 | `; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 65 | |
| 66 | constructor() { |
| 67 | super(); |
| 68 | } |
| 69 | |
| 70 | // See https://lit.dev/docs/components/lifecycle/ |
| 71 | connectedCallback() { |
| 72 | super.connectedCallback(); |
| 73 | } |
| 74 | |
| 75 | // See https://lit.dev/docs/components/lifecycle/ |
| 76 | disconnectedCallback() { |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 77 | super.disconnectedCallback(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | indicator() { |
| 81 | if (this.connection === "disabled") { |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 82 | return ""; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 83 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 84 | return this.connection === "connected" ? "active" : "error"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | render() { |
| 88 | return html` |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 89 | <div class="status-container"> |
| 90 | <span |
| 91 | id="pollingIndicator" |
| 92 | class="polling-indicator ${this.indicator()}" |
| 93 | ></span> |
| 94 | <span id="statusText" class="status-text" |
| 95 | >${this.error || this.message}</span |
| 96 | > |
| 97 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 98 | `; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | declare global { |
| 103 | interface HTMLElementTagNameMap { |
| 104 | "sketch-network-status": SketchNetworkStatus; |
| 105 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 106 | } |