| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| 2 | import { customElement, property, state } from "lit/decorators.js"; |
| 3 | import { DataManager, ConnectionStatus } from "../data"; |
| 4 | import { State, TimelineMessage } from "../types"; |
| 5 | import "./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-view-mode-select") |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 8 | export class SketchViewModeSelect extends LitElement { |
| 9 | // Current active mode |
| 10 | @property() |
| 11 | activeMode: "chat" | "diff" | "charts" | "terminal" = "chat"; |
| 12 | // Header bar: view mode buttons |
| 13 | |
| 14 | // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS. |
| 15 | // Note that these styles only apply to the scope of this web component's |
| 16 | // shadow DOM node, so they won't leak out or collide with CSS declared in |
| 17 | // other components or the containing web page (...unless you want it to do that). |
| 18 | |
| 19 | static styles = css` |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 20 | /* View Mode Button Styles */ |
| 21 | .view-mode-buttons { |
| 22 | display: flex; |
| 23 | gap: 8px; |
| 24 | margin-right: 10px; |
| 25 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 26 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 27 | .emoji-button { |
| 28 | font-size: 18px; |
| 29 | width: 32px; |
| 30 | height: 32px; |
| 31 | display: flex; |
| 32 | align-items: center; |
| 33 | justify-content: center; |
| 34 | background: white; |
| 35 | border: 1px solid #ddd; |
| 36 | border-radius: 4px; |
| 37 | cursor: pointer; |
| 38 | transition: all 0.2s ease; |
| 39 | padding: 0; |
| 40 | line-height: 1; |
| 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 | .emoji-button:hover { |
| 44 | background-color: #f0f0f0; |
| 45 | transform: translateY(-2px); |
| 46 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| 47 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 48 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 49 | .emoji-button.active { |
| 50 | background-color: #e6f7ff; |
| 51 | border-color: #1890ff; |
| 52 | color: #1890ff; |
| 53 | } |
| 54 | `; |
| 55 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 56 | constructor() { |
| 57 | super(); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 58 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 59 | // Binding methods |
| 60 | this._handleViewModeClick = this._handleViewModeClick.bind(this); |
| 61 | this._handleUpdateActiveMode = this._handleUpdateActiveMode.bind(this); |
| 62 | } |
| 63 | |
| 64 | // See https://lit.dev/docs/components/lifecycle/ |
| 65 | connectedCallback() { |
| 66 | super.connectedCallback(); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 67 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 68 | // Listen for update-active-mode events |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 69 | this.addEventListener( |
| 70 | "update-active-mode", |
| 71 | this._handleUpdateActiveMode as EventListener, |
| 72 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 73 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 74 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Handle view mode button clicks |
| 77 | */ |
| 78 | private _handleViewModeClick(mode: "chat" | "diff" | "charts" | "terminal") { |
| 79 | // Dispatch a custom event to notify the app shell to change the view |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 80 | const event = new CustomEvent("view-mode-select", { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 81 | detail: { mode }, |
| 82 | bubbles: true, |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 83 | composed: true, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 84 | }); |
| 85 | this.dispatchEvent(event); |
| 86 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 87 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Handle updates to the active mode |
| 90 | */ |
| 91 | private _handleUpdateActiveMode(event: CustomEvent) { |
| 92 | const { mode } = event.detail; |
| 93 | if (mode) { |
| 94 | this.activeMode = mode; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // See https://lit.dev/docs/components/lifecycle/ |
| 99 | disconnectedCallback() { |
| 100 | super.disconnectedCallback(); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 101 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 102 | // Remove event listeners |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 103 | this.removeEventListener( |
| 104 | "update-active-mode", |
| 105 | this._handleUpdateActiveMode as EventListener, |
| 106 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | render() { |
| 110 | return html` |
| 111 | <div class="view-mode-buttons"> |
| 112 | <button |
| 113 | id="showConversationButton" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 114 | class="emoji-button ${this.activeMode === "chat" ? "active" : ""}" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 115 | title="Conversation View" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 116 | @click=${() => this._handleViewModeClick("chat")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 117 | > |
| 118 | 💬 |
| 119 | </button> |
| 120 | <button |
| 121 | id="showDiffButton" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 122 | class="emoji-button ${this.activeMode === "diff" ? "active" : ""}" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 123 | title="Diff View" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 124 | @click=${() => this._handleViewModeClick("diff")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 125 | > |
| 126 | ± |
| 127 | </button> |
| 128 | <button |
| 129 | id="showChartsButton" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 130 | class="emoji-button ${this.activeMode === "charts" ? "active" : ""}" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 131 | title="Charts View" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 132 | @click=${() => this._handleViewModeClick("charts")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 133 | > |
| 134 | 📈 |
| 135 | </button> |
| 136 | <button |
| 137 | id="showTerminalButton" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 138 | class="emoji-button ${this.activeMode === "terminal" ? "active" : ""}" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 139 | title="Terminal View" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 140 | @click=${() => this._handleViewModeClick("terminal")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 141 | > |
| 142 | 💻 |
| 143 | </button> |
| 144 | </div> |
| 145 | `; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | declare global { |
| 150 | interface HTMLElementTagNameMap { |
| 151 | "sketch-view-mode-select": SketchViewModeSelect; |
| 152 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 153 | } |