blob: e4af00bb8f1f3970b5f5289d617f1b8b97154738 [file] [log] [blame]
Sean McCullough71941bd2025-04-18 13:31:48 -07001import { css, html, LitElement } from "lit";
2import { customElement, property } from "lit/decorators.js";
3import { DataManager, ConnectionStatus } from "../data";
4import { State, TimelineMessage } from "../types";
Sean McCulloughb29f8912025-04-20 15:39:11 -07005import { SketchContainerStatus } from "./sketch-container-status";
Sean McCullough86b56862025-04-18 13:04:03 -07006
Sean McCullough71941bd2025-04-18 13:31:48 -07007@customElement("sketch-network-status")
Sean McCullough86b56862025-04-18 13:04:03 -07008export class SketchNetworkStatus extends LitElement {
Sean McCullough86b56862025-04-18 13:04:03 -07009 @property()
10 connection: string;
Sean McCulloughb29f8912025-04-20 15:39:11 -070011
Sean McCullough86b56862025-04-18 13:04:03 -070012 @property()
13 message: string;
Sean McCulloughb29f8912025-04-20 15:39:11 -070014
Sean McCullough86b56862025-04-18 13:04:03 -070015 @property()
16 error: string;
Sean McCullough71941bd2025-04-18 13:31:48 -070017
Sean McCullough86b56862025-04-18 13:04:03 -070018 // 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 McCullough71941bd2025-04-18 13:31:48 -070024 .status-container {
25 display: flex;
26 align-items: center;
27 }
Sean McCullough86b56862025-04-18 13:04:03 -070028
Sean McCullough71941bd2025-04-18 13:31:48 -070029 .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 McCullough86b56862025-04-18 13:04:03 -070037
Sean McCullough71941bd2025-04-18 13:31:48 -070038 .polling-indicator.active {
39 background-color: #4caf50;
40 animation: pulse 1.5s infinite;
41 }
Sean McCullough86b56862025-04-18 13:04:03 -070042
Sean McCullough71941bd2025-04-18 13:31:48 -070043 .polling-indicator.error {
44 background-color: #f44336;
45 animation: pulse 1.5s infinite;
46 }
Sean McCullough86b56862025-04-18 13:04:03 -070047
Sean McCullough71941bd2025-04-18 13:31:48 -070048 @keyframes pulse {
49 0% {
50 opacity: 1;
51 }
52 50% {
53 opacity: 0.5;
54 }
55 100% {
56 opacity: 1;
57 }
58 }
Sean McCullough86b56862025-04-18 13:04:03 -070059
Sean McCullough71941bd2025-04-18 13:31:48 -070060 .status-text {
61 font-size: 11px;
62 color: #666;
63 }
64 `;
Sean McCullough86b56862025-04-18 13:04:03 -070065
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 McCullough71941bd2025-04-18 13:31:48 -070077 super.disconnectedCallback();
Sean McCullough86b56862025-04-18 13:04:03 -070078 }
79
80 indicator() {
81 if (this.connection === "disabled") {
Sean McCullough71941bd2025-04-18 13:31:48 -070082 return "";
Sean McCullough86b56862025-04-18 13:04:03 -070083 }
Sean McCullough71941bd2025-04-18 13:31:48 -070084 return this.connection === "connected" ? "active" : "error";
Sean McCullough86b56862025-04-18 13:04:03 -070085 }
86
87 render() {
88 return html`
Sean McCullough71941bd2025-04-18 13:31:48 -070089 <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 McCullough86b56862025-04-18 13:04:03 -070098 `;
99 }
100}
101
102declare global {
103 interface HTMLElementTagNameMap {
104 "sketch-network-status": SketchNetworkStatus;
105 }
Sean McCullough71941bd2025-04-18 13:31:48 -0700106}