mirror of
https://github.com/vernu/textbee.git
synced 2026-07-30 17:07:46 -04:00
Introduce a typed data layer under lib/api (query-key factory, response
types, feature hooks) plus shared lib/format and lib/status helpers, and
migrate the canonical dashboard consumers (subscription-info, overview,
device-list, api-keys) onto it, deleting their duplicated inline queries,
mutations and formatters.
List hooks keep the raw { data: [] } envelope in the cache and unwrap
per-observer with react-query `select`, so shared keys like ['devices']
stay compatible with the not-yet-migrated components that still read the
raw shape (avoids a cache-shape collision surfaced by the dashboard e2e).
Adds unit tests for the formatters and the hooks (against MSW). Build,
19 unit tests, and 2 e2e all green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
26 lines
726 B
TypeScript
26 lines
726 B
TypeScript
import { clsx, type ClassValue } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
/**
|
|
* Formats device display name with optional custom name in brackets
|
|
* @param device Device object with brand, model, and optional name
|
|
* @returns Formatted string like "Brand Model" or "Brand Model (Custom Name)"
|
|
*/
|
|
export function formatDeviceName(device: {
|
|
brand?: string
|
|
model?: string
|
|
name?: string | null
|
|
}): string {
|
|
const baseName = `${device.brand ?? ''} ${device.model ?? ''}`.trim()
|
|
|
|
if (device.name && device.name.trim() !== '' && device.name !== baseName) {
|
|
return `${baseName} (${device.name})`
|
|
}
|
|
|
|
return baseName
|
|
}
|