blob: 1012f49da1b75d71087814077905e733f93afef6 [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001import { css, html, LitElement } from "lit";
2import { customElement, property, state } from "lit/decorators.js";
Pokey Rule4097e532025-04-24 18:55:28 +01003import { ConnectionStatus, DataManager } from "../data";
4import { AgentMessage, State } from "../types";
Pokey Rulee2a8c2f2025-04-23 15:09:25 +01005import { aggregateAgentMessages } from "./aggregateAgentMessages";
Pokey Rule4097e532025-04-24 18:55:28 +01006import "./sketch-charts";
7import "./sketch-chat-input";
8import "./sketch-container-status";
9import "./sketch-diff-view";
10import { SketchDiffView } from "./sketch-diff-view";
11import "./sketch-network-status";
12import "./sketch-terminal";
13import "./sketch-timeline";
14import "./sketch-view-mode-select";
15
16import { createRef, ref } from "lit/directives/ref.js";
Sean McCullough86b56862025-04-18 13:04:03 -070017
18type ViewMode = "chat" | "diff" | "charts" | "terminal";
19
20@customElement("sketch-app-shell")
21export class SketchAppShell extends LitElement {
22 // Current view mode (chat, diff, charts, terminal)
23 @state()
24 viewMode: "chat" | "diff" | "charts" | "terminal" = "chat";
25
26 // Current commit hash for diff view
27 @state()
28 currentCommitHash: string = "";
29
Sean McCullough86b56862025-04-18 13:04:03 -070030 // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS.
31 // Note that these styles only apply to the scope of this web component's
32 // shadow DOM node, so they won't leak out or collide with CSS declared in
33 // other components or the containing web page (...unless you want it to do that).
34 static styles = css`
35 :host {
36 display: block;
Sean McCullough71941bd2025-04-18 13:31:48 -070037 font-family:
38 system-ui,
39 -apple-system,
40 BlinkMacSystemFont,
41 "Segoe UI",
42 Roboto,
43 sans-serif;
Sean McCullough86b56862025-04-18 13:04:03 -070044 color: #333;
45 line-height: 1.4;
Pokey Rule4097e532025-04-24 18:55:28 +010046 height: 100vh;
Sean McCullough86b56862025-04-18 13:04:03 -070047 width: 100%;
48 position: relative;
49 overflow-x: hidden;
Pokey Rule4097e532025-04-24 18:55:28 +010050 display: flex;
51 flex-direction: column;
Sean McCullough86b56862025-04-18 13:04:03 -070052 }
53
54 /* Top banner with combined elements */
Pokey Rule4097e532025-04-24 18:55:28 +010055 #top-banner {
Sean McCullough86b56862025-04-18 13:04:03 -070056 display: flex;
Pokey Rule4097e532025-04-24 18:55:28 +010057 align-self: flex-start;
Sean McCullough86b56862025-04-18 13:04:03 -070058 justify-content: space-between;
59 align-items: center;
60 padding: 5px 20px;
61 margin-bottom: 0;
62 border-bottom: 1px solid #eee;
63 gap: 10px;
Sean McCullough86b56862025-04-18 13:04:03 -070064 top: 0;
65 left: 0;
66 right: 0;
67 background: white;
Sean McCullough86b56862025-04-18 13:04:03 -070068 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
69 max-width: 100%;
70 }
71
Pokey Rule4097e532025-04-24 18:55:28 +010072 /* View mode container styles - mirroring timeline.css structure */
73 #view-container {
74 align-self: stretch;
75 overflow-y: auto;
76 flex: 1;
77 }
78
79 #view-container-inner {
80 max-width: 1200px;
81 margin: 0 auto;
82 position: relative;
83 padding-bottom: 10px;
84 padding-top: 10px;
85 }
86
87 #chat-input {
88 align-self: flex-end;
89 width: 100%;
90 box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
91 }
92
Sean McCullough86b56862025-04-18 13:04:03 -070093 .banner-title {
94 font-size: 18px;
95 font-weight: 600;
96 margin: 0;
97 min-width: 6em;
98 white-space: nowrap;
99 overflow: hidden;
100 text-overflow: ellipsis;
101 }
102
103 .chat-title {
104 margin: 0;
105 padding: 0;
106 color: rgba(82, 82, 82, 0.85);
107 font-size: 16px;
108 font-weight: normal;
109 font-style: italic;
110 white-space: nowrap;
111 overflow: hidden;
112 text-overflow: ellipsis;
113 }
114
Sean McCullough86b56862025-04-18 13:04:03 -0700115 /* Allow the container to expand to full width in diff mode */
Pokey Rule4097e532025-04-24 18:55:28 +0100116 #view-container.diff-active {
Sean McCullough86b56862025-04-18 13:04:03 -0700117 max-width: 100%;
118 }
119
120 /* Individual view styles */
121 .chat-view,
122 .diff-view,
123 .chart-view,
124 .terminal-view {
125 display: none; /* Hidden by default */
126 width: 100%;
127 }
128
129 /* Active view styles - these will be applied via JavaScript */
130 .view-active {
131 display: flex;
132 flex-direction: column;
133 }
134
135 .title-container {
136 display: flex;
137 flex-direction: column;
138 white-space: nowrap;
139 overflow: hidden;
140 text-overflow: ellipsis;
141 max-width: 33%;
142 }
143
144 .refresh-control {
145 display: flex;
146 align-items: center;
147 margin-bottom: 0;
148 flex-wrap: nowrap;
149 white-space: nowrap;
150 flex-shrink: 0;
151 }
152
153 .refresh-button {
154 background: #4caf50;
155 color: white;
156 border: none;
157 padding: 4px 10px;
158 border-radius: 4px;
159 cursor: pointer;
160 font-size: 12px;
161 margin-right: 5px;
162 }
163
164 .stop-button:hover {
165 background-color: #c82333 !important;
166 }
167
168 .poll-updates {
169 display: flex;
170 align-items: center;
171 margin: 0 5px;
172 font-size: 12px;
173 }
174 `;
175
176 // Header bar: Network connection status details
177 @property()
178 connectionStatus: ConnectionStatus = "disconnected";
179
180 @property()
181 connectionErrorMessage: string = "";
182
183 @property()
184 messageStatus: string = "";
185
186 // Chat messages
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100187 @property({ attribute: false })
Sean McCulloughd9f13372025-04-21 15:08:49 -0700188 messages: AgentMessage[] = [];
Sean McCullough86b56862025-04-18 13:04:03 -0700189
190 @property()
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000191 set title(value: string) {
192 const oldValue = this._title;
193 this._title = value;
194 this.requestUpdate("title", oldValue);
195 // Update document title when title property changes
196 this.updateDocumentTitle();
197 }
198
199 get title(): string {
200 return this._title;
201 }
202
203 private _title: string = "";
Sean McCullough86b56862025-04-18 13:04:03 -0700204
205 private dataManager = new DataManager();
206
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100207 @property({ attribute: false })
Sean McCulloughd9f13372025-04-21 15:08:49 -0700208 containerState: State = {
209 title: "",
210 os: "",
211 message_count: 0,
212 hostname: "",
213 working_dir: "",
214 initial_commit: "",
215 };
Sean McCullough86b56862025-04-18 13:04:03 -0700216
Sean McCullough86b56862025-04-18 13:04:03 -0700217 // Mutation observer to detect when new messages are added
218 private mutationObserver: MutationObserver | null = null;
219
220 constructor() {
221 super();
222
223 // Binding methods to this
224 this._handleViewModeSelect = this._handleViewModeSelect.bind(this);
Sean McCullough86b56862025-04-18 13:04:03 -0700225 this._handleShowCommitDiff = this._handleShowCommitDiff.bind(this);
226 this._handlePopState = this._handlePopState.bind(this);
227 }
228
229 // See https://lit.dev/docs/components/lifecycle/
230 connectedCallback() {
231 super.connectedCallback();
232
233 // Initialize client-side nav history.
234 const url = new URL(window.location.href);
235 const mode = url.searchParams.get("view") || "chat";
236 window.history.replaceState({ mode }, "", url.toString());
237
238 this.toggleViewMode(mode as ViewMode, false);
239 // Add popstate event listener to handle browser back/forward navigation
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100240 window.addEventListener("popstate", this._handlePopState);
Sean McCullough86b56862025-04-18 13:04:03 -0700241
242 // Add event listeners
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100243 window.addEventListener("view-mode-select", this._handleViewModeSelect);
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100244 window.addEventListener("show-commit-diff", this._handleShowCommitDiff);
Sean McCullough86b56862025-04-18 13:04:03 -0700245
246 // register event listeners
247 this.dataManager.addEventListener(
248 "dataChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700249 this.handleDataChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700250 );
251 this.dataManager.addEventListener(
252 "connectionStatusChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700253 this.handleConnectionStatusChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700254 );
255
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000256 // Set initial document title
257 this.updateDocumentTitle();
258
Sean McCullough86b56862025-04-18 13:04:03 -0700259 // Initialize the data manager
260 this.dataManager.initialize();
261 }
262
263 // See https://lit.dev/docs/components/lifecycle/
264 disconnectedCallback() {
265 super.disconnectedCallback();
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100266 window.removeEventListener("popstate", this._handlePopState);
Sean McCullough86b56862025-04-18 13:04:03 -0700267
268 // Remove event listeners
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100269 window.removeEventListener("view-mode-select", this._handleViewModeSelect);
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100270 window.removeEventListener("show-commit-diff", this._handleShowCommitDiff);
Sean McCullough86b56862025-04-18 13:04:03 -0700271
272 // unregister data manager event listeners
273 this.dataManager.removeEventListener(
274 "dataChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700275 this.handleDataChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700276 );
277 this.dataManager.removeEventListener(
278 "connectionStatusChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700279 this.handleConnectionStatusChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700280 );
281
282 // Disconnect mutation observer if it exists
283 if (this.mutationObserver) {
Sean McCullough86b56862025-04-18 13:04:03 -0700284 this.mutationObserver.disconnect();
285 this.mutationObserver = null;
286 }
287 }
288
Sean McCullough71941bd2025-04-18 13:31:48 -0700289 updateUrlForViewMode(mode: "chat" | "diff" | "charts" | "terminal"): void {
Sean McCullough86b56862025-04-18 13:04:03 -0700290 // Get the current URL without search parameters
291 const url = new URL(window.location.href);
292
293 // Clear existing parameters
294 url.search = "";
295
296 // Only add view parameter if not in default chat view
297 if (mode !== "chat") {
298 url.searchParams.set("view", mode);
Sean McCullough71941bd2025-04-18 13:31:48 -0700299 const diffView = this.shadowRoot?.querySelector(
Philip Zeyliger72682df2025-04-23 13:09:46 -0700300 ".diff-view",
Sean McCullough71941bd2025-04-18 13:31:48 -0700301 ) as SketchDiffView;
Sean McCullough86b56862025-04-18 13:04:03 -0700302
303 // If in diff view and there's a commit hash, include that too
304 if (mode === "diff" && diffView.commitHash) {
305 url.searchParams.set("commit", diffView.commitHash);
306 }
307 }
308
309 // Update the browser history without reloading the page
310 window.history.pushState({ mode }, "", url.toString());
311 }
312
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100313 private _handlePopState(event: PopStateEvent) {
Sean McCullough86b56862025-04-18 13:04:03 -0700314 if (event.state && event.state.mode) {
315 this.toggleViewMode(event.state.mode, false);
316 } else {
317 this.toggleViewMode("chat", false);
318 }
319 }
320
321 /**
322 * Handle view mode selection event
323 */
324 private _handleViewModeSelect(event: CustomEvent) {
325 const mode = event.detail.mode as "chat" | "diff" | "charts" | "terminal";
326 this.toggleViewMode(mode, true);
327 }
328
329 /**
330 * Handle show commit diff event
331 */
332 private _handleShowCommitDiff(event: CustomEvent) {
333 const { commitHash } = event.detail;
334 if (commitHash) {
335 this.showCommitDiff(commitHash);
336 }
337 }
338
339 /**
Sean McCullough86b56862025-04-18 13:04:03 -0700340 * Listen for commit diff event
341 * @param commitHash The commit hash to show diff for
342 */
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100343 private showCommitDiff(commitHash: string): void {
Sean McCullough86b56862025-04-18 13:04:03 -0700344 // Store the commit hash
345 this.currentCommitHash = commitHash;
346
347 // Switch to diff view
Sean McCullough71941bd2025-04-18 13:31:48 -0700348 this.toggleViewMode("diff", true);
Sean McCullough86b56862025-04-18 13:04:03 -0700349
350 // Wait for DOM update to complete
351 this.updateComplete.then(() => {
352 // Get the diff view component
353 const diffView = this.shadowRoot?.querySelector("sketch-diff-view");
354 if (diffView) {
355 // Call the showCommitDiff method
356 (diffView as any).showCommitDiff(commitHash);
357 }
358 });
359 }
360
361 /**
362 * Toggle between different view modes: chat, diff, charts, terminal
363 */
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100364 private toggleViewMode(mode: ViewMode, updateHistory: boolean): void {
Sean McCullough86b56862025-04-18 13:04:03 -0700365 // Don't do anything if the mode is already active
366 if (this.viewMode === mode) return;
367
368 // Update the view mode
369 this.viewMode = mode;
370
371 if (updateHistory) {
372 // Update URL with the current view mode
373 this.updateUrlForViewMode(mode);
374 }
375
376 // Wait for DOM update to complete
377 this.updateComplete.then(() => {
378 // Update active view
Pokey Rule4097e532025-04-24 18:55:28 +0100379 const viewContainer = this.shadowRoot?.querySelector("#view-container");
Sean McCullough86b56862025-04-18 13:04:03 -0700380 const chatView = this.shadowRoot?.querySelector(".chat-view");
381 const diffView = this.shadowRoot?.querySelector(".diff-view");
382 const chartView = this.shadowRoot?.querySelector(".chart-view");
383 const terminalView = this.shadowRoot?.querySelector(".terminal-view");
384
385 // Remove active class from all views
386 chatView?.classList.remove("view-active");
387 diffView?.classList.remove("view-active");
388 chartView?.classList.remove("view-active");
389 terminalView?.classList.remove("view-active");
390
391 // Add/remove diff-active class on view container
392 if (mode === "diff") {
393 viewContainer?.classList.add("diff-active");
394 } else {
395 viewContainer?.classList.remove("diff-active");
396 }
397
398 // Add active class to the selected view
399 switch (mode) {
400 case "chat":
401 chatView?.classList.add("view-active");
402 break;
403 case "diff":
404 diffView?.classList.add("view-active");
405 // Load diff content if we have a diff view
406 const diffViewComp =
407 this.shadowRoot?.querySelector("sketch-diff-view");
408 if (diffViewComp && this.currentCommitHash) {
409 (diffViewComp as any).showCommitDiff(this.currentCommitHash);
410 } else if (diffViewComp) {
411 (diffViewComp as any).loadDiffContent();
412 }
413 break;
414 case "charts":
415 chartView?.classList.add("view-active");
416 break;
417 case "terminal":
418 terminalView?.classList.add("view-active");
419 break;
420 }
421
422 // Update view mode buttons
423 const viewModeSelect = this.shadowRoot?.querySelector(
Philip Zeyliger72682df2025-04-23 13:09:46 -0700424 "sketch-view-mode-select",
Sean McCullough86b56862025-04-18 13:04:03 -0700425 );
426 if (viewModeSelect) {
427 const event = new CustomEvent("update-active-mode", {
428 detail: { mode },
429 bubbles: true,
430 composed: true,
431 });
432 viewModeSelect.dispatchEvent(event);
433 }
434
435 // FIXME: This is a hack to get vega chart in sketch-charts.ts to work properly
436 // When the chart is in the background, its container has a width of 0, so vega
437 // renders width 0 and only changes that width on a resize event.
438 // See https://github.com/vega/react-vega/issues/85#issuecomment-1826421132
439 window.dispatchEvent(new Event("resize"));
440 });
441 }
442
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000443 /**
444 * Updates the document title based on current title and connection status
445 */
446 private updateDocumentTitle(): void {
447 let docTitle = `sk: ${this.title || "untitled"}`;
448
449 // Add red circle emoji if disconnected
450 if (this.connectionStatus === "disconnected") {
451 docTitle += " 🔴";
452 }
453
454 document.title = docTitle;
455 }
456
Sean McCullough86b56862025-04-18 13:04:03 -0700457 private handleDataChanged(eventData: {
458 state: State;
Sean McCulloughd9f13372025-04-21 15:08:49 -0700459 newMessages: AgentMessage[];
Sean McCullough86b56862025-04-18 13:04:03 -0700460 isFirstFetch?: boolean;
461 }): void {
462 const { state, newMessages, isFirstFetch } = eventData;
463
464 // Check if this is the first data fetch or if there are new messages
465 if (isFirstFetch) {
Sean McCullough86b56862025-04-18 13:04:03 -0700466 this.messageStatus = "Initial messages loaded";
467 } else if (newMessages && newMessages.length > 0) {
Sean McCullough86b56862025-04-18 13:04:03 -0700468 this.messageStatus = "Updated just now";
Sean McCullough86b56862025-04-18 13:04:03 -0700469 } else {
470 this.messageStatus = "No new messages";
471 }
472
473 // Update state if we received it
474 if (state) {
475 this.containerState = state;
476 this.title = state.title;
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000477
478 // Update document title when sketch title changes
479 this.updateDocumentTitle();
Sean McCullough86b56862025-04-18 13:04:03 -0700480 }
481
Sean McCullough86b56862025-04-18 13:04:03 -0700482 // Update messages
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100483 this.messages = aggregateAgentMessages(this.messages, newMessages);
Sean McCullough86b56862025-04-18 13:04:03 -0700484 }
485
486 private handleConnectionStatusChanged(
487 status: ConnectionStatus,
Philip Zeyliger72682df2025-04-23 13:09:46 -0700488 errorMessage?: string,
Sean McCullough86b56862025-04-18 13:04:03 -0700489 ): void {
490 this.connectionStatus = status;
491 this.connectionErrorMessage = errorMessage || "";
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000492
493 // Update document title when connection status changes
494 this.updateDocumentTitle();
Sean McCullough86b56862025-04-18 13:04:03 -0700495 }
496
497 async _sendChat(e: CustomEvent) {
498 console.log("app shell: _sendChat", e);
499 const message = e.detail.message?.trim();
500 if (message == "") {
501 return;
502 }
503 try {
504 // Send the message to the server
505 const response = await fetch("chat", {
506 method: "POST",
507 headers: {
508 "Content-Type": "application/json",
509 },
510 body: JSON.stringify({ message }),
511 });
512
513 if (!response.ok) {
514 const errorData = await response.text();
515 throw new Error(`Server error: ${response.status} - ${errorData}`);
516 }
Sean McCullough86b56862025-04-18 13:04:03 -0700517
Philip Zeyliger73db6052025-04-23 13:09:07 -0700518 // TOOD(philip): If the data manager is getting messages out of order, there's a bug?
Sean McCullough86b56862025-04-18 13:04:03 -0700519 // Reset data manager state to force a full refresh after sending a message
520 // This ensures we get all messages in the correct order
521 // Use private API for now - TODO: add a resetState() method to DataManager
522 (this.dataManager as any).nextFetchIndex = 0;
523 (this.dataManager as any).currentFetchStartIndex = 0;
524
Sean McCullough86b56862025-04-18 13:04:03 -0700525 // // If in diff view, switch to conversation view
526 // if (this.viewMode === "diff") {
527 // await this.toggleViewMode("chat");
528 // }
529
530 // Refresh the timeline data to show the new message
531 await this.dataManager.fetchData();
Sean McCullough86b56862025-04-18 13:04:03 -0700532 } catch (error) {
533 console.error("Error sending chat message:", error);
534 const statusText = document.getElementById("statusText");
535 if (statusText) {
536 statusText.textContent = "Error sending message";
537 }
538 }
539 }
540
Pokey Rule4097e532025-04-24 18:55:28 +0100541 private scrollContainerRef = createRef<HTMLElement>();
542
Sean McCullough86b56862025-04-18 13:04:03 -0700543 render() {
544 return html`
Pokey Rule4097e532025-04-24 18:55:28 +0100545 <div id="top-banner">
Sean McCullough86b56862025-04-18 13:04:03 -0700546 <div class="title-container">
547 <h1 class="banner-title">sketch</h1>
548 <h2 id="chatTitle" class="chat-title">${this.title}</h2>
549 </div>
550
551 <sketch-container-status
552 .state=${this.containerState}
553 ></sketch-container-status>
554
555 <div class="refresh-control">
556 <sketch-view-mode-select></sketch-view-mode-select>
557
558 <button id="stopButton" class="refresh-button stop-button">
559 Stop
560 </button>
561
562 <div class="poll-updates">
563 <input type="checkbox" id="pollToggle" checked />
564 <label for="pollToggle">Poll</label>
565 </div>
566
567 <sketch-network-status
568 message=${this.messageStatus}
569 connection=${this.connectionStatus}
570 error=${this.connectionErrorMessage}
571 ></sketch-network-status>
572 </div>
573 </div>
574
Pokey Rule4097e532025-04-24 18:55:28 +0100575 <div id="view-container" ${ref(this.scrollContainerRef)}>
576 <div id="view-container-inner">
577 <div
578 class="chat-view ${this.viewMode === "chat" ? "view-active" : ""}"
579 >
580 <sketch-timeline
581 .messages=${this.messages}
582 .scrollContainer=${this.scrollContainerRef}
583 ></sketch-timeline>
584 </div>
585 <div
586 class="diff-view ${this.viewMode === "diff" ? "view-active" : ""}"
587 >
588 <sketch-diff-view
589 .commitHash=${this.currentCommitHash}
590 ></sketch-diff-view>
591 </div>
592 <div
593 class="chart-view ${this.viewMode === "charts"
594 ? "view-active"
595 : ""}"
596 >
597 <sketch-charts .messages=${this.messages}></sketch-charts>
598 </div>
599 <div
600 class="terminal-view ${this.viewMode === "terminal"
601 ? "view-active"
602 : ""}"
603 >
604 <sketch-terminal></sketch-terminal>
605 </div>
Sean McCullough86b56862025-04-18 13:04:03 -0700606 </div>
607 </div>
608
Pokey Rule4097e532025-04-24 18:55:28 +0100609 <div id="chat-input">
610 <sketch-chat-input @send-chat="${this._sendChat}"></sketch-chat-input>
611 </div>
Sean McCullough86b56862025-04-18 13:04:03 -0700612 `;
613 }
614
615 /**
Sean McCullough86b56862025-04-18 13:04:03 -0700616 * Lifecycle callback when component is first connected to DOM
617 */
618 firstUpdated(): void {
619 if (this.viewMode !== "chat") {
620 return;
621 }
622
623 // Initial scroll to bottom when component is first rendered
624 setTimeout(
625 () => this.scrollTo({ top: this.scrollHeight, behavior: "smooth" }),
Philip Zeyliger72682df2025-04-23 13:09:46 -0700626 50,
Sean McCullough86b56862025-04-18 13:04:03 -0700627 );
628
Sean McCullough71941bd2025-04-18 13:31:48 -0700629 const pollToggleCheckbox = this.renderRoot?.querySelector(
Philip Zeyliger72682df2025-04-23 13:09:46 -0700630 "#pollToggle",
Sean McCullough71941bd2025-04-18 13:31:48 -0700631 ) as HTMLInputElement;
Sean McCullough86b56862025-04-18 13:04:03 -0700632 pollToggleCheckbox?.addEventListener("change", () => {
633 this.dataManager.setPollingEnabled(pollToggleCheckbox.checked);
634 if (!pollToggleCheckbox.checked) {
635 this.connectionStatus = "disabled";
636 this.messageStatus = "Polling stopped";
637 } else {
638 this.messageStatus = "Polling for updates...";
639 }
640 });
641 }
642}
643
644declare global {
645 interface HTMLElementTagNameMap {
646 "sketch-app-shell": SketchAppShell;
647 }
648}