/** * The usage page's card chrome: the family settings card whose header holds * the plugin switch, and the display rows the body closes with. * @module @linxin666/dsh-usage/client/UsagePage */ import type { ReactNode } from 'react' import { t } from './locales.ts' import styles from './usage.module.css' import { ChoiceField, PluginSettingsCard, ToggleSwitch, ValueField } from './PluginSettingsCard.tsx' import { POLL_INTERVAL_RANGE, SPEND_CURRENCIES, type UsageSettingsCardFace, type UsageSettingsCardState } from './usage-settings-card.ts' /** * The page's card: the plugin switch in the header, the statistics and the * display rows in the body. A switched-off plugin keeps only the header, whose * line says how to bring it back; a refused write keeps the body, so the * failure line under the rows stays readable. */ export function UsagePage(props: { card: UsageSettingsCardState; face: UsageSettingsCardFace; enabled: boolean; children: ReactNode }): ReactNode { const { card, face, enabled } = props return ( ) } /** * The display rows under the statistics. Each control writes through the card * form: the currency pick at once, a typed number after a pause or on Enter. * The rate only matters while spend shows in dollars, so it appears then. */ function SettingsRows(props: { card: UsageSettingsCardState; face: UsageSettingsCardFace }): ReactNode { const { card, face } = props const fieldProps = { overriddenLabel: t('settings.overridden'), resetLabel: t('settings.reset'), invalidLabel: t('settings.invalidNumber'), disabled: !card.writable, } return (

{t('usage.config.title')}

{ face.edit('pollIntervalSec', text) }} onReset={() => { face.resetField('pollIntervalSec') }} /> ({ value: currency, label: currency }))} {...fieldProps} {...card.spendCurrency} onEdit={(text) => { face.edit('spendCurrency', text) }} onReset={() => { face.resetField('spendCurrency') }} /> {card.spendCurrency.text === 'USD' ? ( { face.edit('cnyPerUsd', text) }} onReset={() => { face.resetField('cnyPerUsd') }} /> ) : null}
) }