-
Notifications
You must be signed in to change notification settings - Fork 0
feat(frontend): header chrome with live connection status #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Top chrome for the chat window. Shows the active channel, the platform | ||
| // it belongs to, and a live connection indicator fed by the supervisor's | ||
| // `sidecar_status` event. Purely presentational: no commands invoked, so | ||
| // a broken supervisor can't brick the UI. | ||
|
|
||
| import { Component, Show, createSignal, onCleanup, onMount } from "solid-js"; | ||
| import { listen, type UnlistenFn } from "@tauri-apps/api/event"; | ||
| import { | ||
| indicatorFor, | ||
| type SidecarState, | ||
| type SidecarStatus, | ||
| } from "../lib/sidecarStatus"; | ||
|
|
||
| export interface HeaderProps { | ||
| login: string; | ||
| } | ||
|
|
||
| const Header: Component<HeaderProps> = (props) => { | ||
| const [state, setState] = createSignal<SidecarState | null>(null); | ||
| let unlisten: UnlistenFn | undefined; | ||
| // listen() is async, so a fast unmount can race the registration: if | ||
| // onCleanup runs first, `unlisten` is still undefined and the listener | ||
| // would leak when the promise resolves later. Track disposal explicitly | ||
| // so the late-arriving handle can be torn down immediately. | ||
| let disposed = false; | ||
|
|
||
| onMount(() => { | ||
| listen<SidecarStatus>("sidecar_status", (evt) => { | ||
| setState(evt.payload.state); | ||
| }) | ||
| .then((next) => { | ||
| if (disposed) { | ||
| next(); | ||
| return; | ||
| } | ||
| unlisten = next; | ||
| }) | ||
| .catch((err: unknown) => { | ||
| console.error("failed to subscribe to sidecar_status", err); | ||
| }); | ||
| }); | ||
|
|
||
| onCleanup(() => { | ||
| disposed = true; | ||
| unlisten?.(); | ||
| unlisten = undefined; | ||
| }); | ||
|
|
||
| return ( | ||
| <header | ||
| style={{ | ||
| display: "flex", | ||
| "align-items": "center", | ||
| gap: "10px", | ||
| padding: "8px 12px", | ||
| "border-bottom": "1px solid #2a2a2e", | ||
| background: "#18181b", | ||
| "font-family": | ||
| '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', | ||
| "font-size": "13px", | ||
| color: "#efeff1", | ||
| "flex-shrink": 0, | ||
| }} | ||
| > | ||
| <span | ||
| title="Twitch" | ||
| aria-label="Twitch" | ||
| style={{ | ||
| display: "inline-flex", | ||
| "align-items": "center", | ||
| "justify-content": "center", | ||
| width: "20px", | ||
| height: "20px", | ||
| "border-radius": "4px", | ||
| background: "#9146ff", | ||
| color: "#fff", | ||
| "font-weight": 700, | ||
| "font-size": "12px", | ||
| }} | ||
| > | ||
| T | ||
| </span> | ||
| <span style={{ "font-weight": 600 }}>{props.login}</span> | ||
| <span style={{ flex: 1 }} /> | ||
| <ConnectionChip state={state()} /> | ||
| </header> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectionChip: Component<{ state: SidecarState | null }> = (props) => { | ||
| const info = () => indicatorFor(props.state); | ||
| return ( | ||
| <span | ||
| data-testid="connection-chip" | ||
| data-state={props.state ?? "initial"} | ||
| style={{ | ||
| display: "inline-flex", | ||
| "align-items": "center", | ||
| gap: "6px", | ||
| padding: "2px 8px", | ||
| "border-radius": "10px", | ||
| background: "#1f1f23", | ||
| border: "1px solid #2a2a2e", | ||
| "font-size": "12px", | ||
| color: "#c8c8d0", | ||
| }} | ||
| > | ||
| <Dot color={info().color} /> | ||
| <Show when={info().label}>{info().label}</Show> | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| const Dot: Component<{ color: string }> = (props) => { | ||
| return ( | ||
| <span | ||
| style={{ | ||
| display: "inline-block", | ||
| width: "8px", | ||
| height: "8px", | ||
| "border-radius": "50%", | ||
| background: props.color, | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default Header; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { indicatorFor } from "./sidecarStatus"; | ||
|
|
||
| describe("indicatorFor", () => { | ||
| it("running → green connected", () => { | ||
| expect(indicatorFor("running")).toEqual({ | ||
| label: "Connected", | ||
| color: "#3fb950", | ||
| }); | ||
| }); | ||
|
|
||
| it("spawning and backoff share the amber connecting indicator", () => { | ||
| expect(indicatorFor("spawning")).toEqual({ | ||
| label: "Connecting", | ||
| color: "#d29922", | ||
| }); | ||
| expect(indicatorFor("backoff")).toEqual({ | ||
| label: "Connecting", | ||
| color: "#d29922", | ||
| }); | ||
| }); | ||
|
|
||
| it("waiting_for_auth surfaces a sign-in hint", () => { | ||
| expect(indicatorFor("waiting_for_auth")).toEqual({ | ||
| label: "Waiting for sign-in", | ||
| color: "#d29922", | ||
| }); | ||
| }); | ||
|
|
||
| it("unhealthy and terminated are distinct", () => { | ||
| expect(indicatorFor("unhealthy")).toEqual({ | ||
| label: "Unhealthy", | ||
| color: "#db6d28", | ||
| }); | ||
| expect(indicatorFor("terminated")).toEqual({ | ||
| label: "Disconnected", | ||
| color: "#f85149", | ||
| }); | ||
| }); | ||
|
|
||
| it("null before any event reports a starting state", () => { | ||
| expect(indicatorFor(null)).toEqual({ | ||
| label: "Starting", | ||
| color: "#6e7681", | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Pure state→indicator mapping shared with the header component. | ||
| // Split out so unit tests don't need to resolve the Solid/Tauri | ||
| // component module graph. | ||
|
|
||
| export type SidecarState = | ||
| | "spawning" | ||
| | "waiting_for_auth" | ||
| | "backoff" | ||
| | "running" | ||
| | "unhealthy" | ||
| | "terminated"; | ||
|
|
||
| export interface SidecarStatus { | ||
| state: SidecarState; | ||
| attempt: number; | ||
| backoff_ms?: number; | ||
| } | ||
|
|
||
| export interface Indicator { | ||
| label: string; | ||
| color: string; | ||
| } | ||
|
|
||
| export function indicatorFor(state: SidecarState | null): Indicator { | ||
| switch (state) { | ||
| case "running": | ||
| return { label: "Connected", color: "#3fb950" }; | ||
| case "spawning": | ||
| case "backoff": | ||
| return { label: "Connecting", color: "#d29922" }; | ||
| case "waiting_for_auth": | ||
| return { label: "Waiting for sign-in", color: "#d29922" }; | ||
| case "unhealthy": | ||
| return { label: "Unhealthy", color: "#db6d28" }; | ||
| case "terminated": | ||
| return { label: "Disconnected", color: "#f85149" }; | ||
| default: | ||
| return { label: "Starting", color: "#6e7681" }; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.