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.
This commit is contained in:
Anish Sarkar 2026-04-25 01:47:37 +05:30
parent 1c18735d38
commit 68156d2e74
5 changed files with 32 additions and 60 deletions

View file

@ -1,5 +1,6 @@
import { setIcon } from "obsidian";
import type { StatusKind, StatusState } from "./types";
import { STATUS_VISUALS } from "./status-visuals";
import type { StatusState } from "./types";
/**
* Tiny status-bar adornment.
@ -8,21 +9,6 @@ import type { StatusKind, StatusState } from "./types";
* and Obsidian's lint doesn't complain about innerHTML.
*/
interface StatusVisual {
icon: string;
label: string;
cls: string;
}
const VISUALS: Record<StatusKind, StatusVisual> = {
idle: { icon: "check-circle", label: "Synced", cls: "" },
syncing: { icon: "refresh-ccw", label: "Syncing", cls: "" },
queued: { icon: "clock", label: "Queued", cls: "" },
offline: { icon: "wifi-off", label: "Offline", cls: "" },
"auth-error": { icon: "user-x", label: "Auth error", cls: "surfsense-status--err" },
error: { icon: "alert-circle", label: "Error", cls: "surfsense-status--err" },
};
export class StatusBar {
private readonly el: HTMLElement;
private readonly icon: HTMLElement;
@ -41,9 +27,9 @@ export class StatusBar {
}
update(state: StatusState): void {
const visual = VISUALS[state.kind];
const visual = STATUS_VISUALS[state.kind];
this.el.removeClass("surfsense-status--err");
if (visual.cls) this.el.addClass(visual.cls);
if (visual.isError) this.el.addClass("surfsense-status--err");
setIcon(this.icon, visual.icon);
let label = `SurfSense: ${visual.label}`;