SurfSense/surfsense_obsidian/src/status-bar.ts
Anish Sarkar 68156d2e74 refactor: centralize status visuals and improve connection indicator logic
- Introduced a new `status-visuals.ts` file to centralize status icons and labels for consistency across the plugin.
- Updated connection indicator logic in the settings tab to utilize the new centralized visuals.
- Removed deprecated connection visual methods to streamline the codebase.
- Enhanced error handling in the status bar to reflect the new status visuals structure.
2026-04-25 01:47:37 +05:30

46 lines
1.4 KiB
TypeScript

import { setIcon } from "obsidian";
import { STATUS_VISUALS } from "./status-visuals";
import type { StatusState } from "./types";
/**
* Tiny status-bar adornment.
*
* Plain DOM (no HTML strings, no CSS-in-JS) so it stays cheap on mobile
* and Obsidian's lint doesn't complain about innerHTML.
*/
export class StatusBar {
private readonly el: HTMLElement;
private readonly icon: HTMLElement;
private readonly text: HTMLElement;
constructor(host: HTMLElement, onClick?: () => void) {
this.el = host;
this.el.addClass("surfsense-status");
this.icon = this.el.createSpan({ cls: "surfsense-status__icon" });
this.text = this.el.createSpan({ cls: "surfsense-status__text" });
if (onClick) {
this.el.addClass("surfsense-status--clickable");
this.el.addEventListener("click", onClick);
}
this.update({ kind: "idle", queueDepth: 0 });
}
update(state: StatusState): void {
const visual = STATUS_VISUALS[state.kind];
this.el.removeClass("surfsense-status--err");
if (visual.isError) this.el.addClass("surfsense-status--err");
setIcon(this.icon, visual.icon);
let label = `SurfSense: ${visual.label}`;
if (state.queueDepth > 0 && state.kind !== "idle") {
label += ` (${state.queueDepth})`;
}
this.text.setText(label);
this.el.setAttr(
"aria-label",
state.detail ? `${label}${state.detail}` : label,
);
this.el.setAttr("title", state.detail ?? label);
}
}