mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
44c6fbf372
Every date in TREK was written in the interface language's format, and English is en-US, so an English interface always showed and read mm/dd/yyyy with no way to change it. A few native date inputs followed the browser instead, so one screen could mix two formats. date_format is now a user setting with an admin default, next to the time format: automatic (the language's format, as before), YYYY-MM-DD, YYYY/MM/DD, DD.MM.YYYY, DD/MM/YYYY or MM/DD/YYYY. The date picker shows, pre-fills, hints and reads typed dates in it, and every date written in numbers across the app (lists, cards, admin panels, CSV and PDF exports) goes through one formatter. Dates written with a month name keep the language's wording. The remaining native date inputs are the shared picker now. The display settings MCP tool reads and writes the key. Closes #2971
123 lines
4.4 KiB
TypeScript
123 lines
4.4 KiB
TypeScript
import React from 'react'
|
|
import { Plug, Save, RefreshCw, Unplug } from 'lucide-react'
|
|
import { useTranslation } from '../../../i18n'
|
|
import { useFormatDate } from '../../../hooks/useDateFormat'
|
|
import { useDawarichConnection } from '../../../hooks/useDawarichConnection'
|
|
import { MSetCard, MSetRow, MSetInput, MSetButton, MSetHint } from './MSettingsUi'
|
|
import MToggle from '../../components/MToggle'
|
|
|
|
/**
|
|
* Phone twin of components/Settings/DawarichConnectionSection.
|
|
*
|
|
* Presentation only: every piece of behaviour lives in `useDawarichConnection`,
|
|
* which both shells share. That is not tidiness — SonarCloud allows 3%
|
|
* duplicated lines on a PR's new code, and a second copy of the connect / test /
|
|
* sync logic would spend the whole budget on its own.
|
|
*/
|
|
export default function MDawarichConnectionSection(): React.ReactElement {
|
|
const { t } = useTranslation()
|
|
const { formatDateTime } = useFormatDate()
|
|
const S = useDawarichConnection()
|
|
|
|
return (
|
|
<MSetCard title={t('dawarich.title')} icon={Plug} className="mt-3">
|
|
<MSetHint className="mt-0">{t('dawarich.intro')}</MSetHint>
|
|
|
|
<div className="mt-3 space-y-3">
|
|
<div>
|
|
<MSetInput
|
|
type="url"
|
|
inputMode="url"
|
|
value={S.url}
|
|
onChange={e => S.setUrl(e.target.value)}
|
|
placeholder="https://dawarich.example.com"
|
|
aria-label={t('dawarich.url')}
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<MSetInput
|
|
type="password"
|
|
value={S.apiKey}
|
|
onChange={e => S.setApiKey(e.target.value)}
|
|
autoComplete="off"
|
|
placeholder={S.connected && !S.apiKey ? '••••••••' : t('dawarich.apiKeyPlaceholder')}
|
|
aria-label={t('dawarich.apiKey')}
|
|
/>
|
|
<MSetHint>{t('dawarich.apiKeyHint')}</MSetHint>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-1">
|
|
<MSetRow
|
|
first
|
|
label={t('dawarich.syncEnabled')}
|
|
sub={t('dawarich.syncEnabledHint')}
|
|
trailing={
|
|
<MToggle checked={S.syncEnabled} onChange={S.toggleSync} ariaLabel={t('dawarich.syncEnabled')} />
|
|
}
|
|
/>
|
|
<MSetRow
|
|
label={t('dawarich.allowInsecureTls')}
|
|
sub={t('dawarich.allowInsecureTlsHint')}
|
|
trailing={
|
|
<MToggle
|
|
checked={S.allowInsecureTls}
|
|
onChange={S.toggleInsecureTls}
|
|
ariaLabel={t('dawarich.allowInsecureTls')}
|
|
/>
|
|
}
|
|
/>
|
|
</div>
|
|
|
|
<div className="mt-3 flex flex-wrap items-center gap-2">
|
|
<MSetButton onClick={S.save} disabled={S.saving || S.loading || !S.canSave}>
|
|
<Save size={14} /> {t('common.save')}
|
|
</MSetButton>
|
|
<MSetButton variant="ghost" onClick={S.test} disabled={S.testing || S.loading || !S.url.trim()}>
|
|
<Plug size={14} /> {t('dawarich.test.button')}
|
|
</MSetButton>
|
|
{S.connected && (
|
|
<MSetButton variant="ghost" onClick={S.syncNow} disabled={S.syncing}>
|
|
<RefreshCw size={14} className={S.syncing ? 'animate-spin' : ''} /> {t('dawarich.syncNow')}
|
|
</MSetButton>
|
|
)}
|
|
</div>
|
|
|
|
<div className="mt-3 space-y-[4px]">
|
|
<p className="font-geist text-[0.6875rem] font-semibold text-m-ink">
|
|
{S.connected ? t('dawarich.connected') : t('dawarich.notConnected')}
|
|
</p>
|
|
{S.probeMessage && (
|
|
<p className="font-geist text-[0.625rem] leading-relaxed text-m-muted">{S.probeMessage}</p>
|
|
)}
|
|
{S.connected && (
|
|
<p className="font-geist text-[0.625rem] leading-relaxed text-m-muted">
|
|
{S.lastSyncAt
|
|
? t('dawarich.lastSync', { when: formatDateTime(new Date(S.lastSyncAt)) })
|
|
: t('dawarich.neverSynced')}
|
|
</p>
|
|
)}
|
|
{S.lastSyncError && (
|
|
<p className="font-geist text-[0.625rem] leading-relaxed text-[color:var(--m-st-danger)]">
|
|
{S.lastSyncError}
|
|
</p>
|
|
)}
|
|
{S.capabilities?.serverVersion && (
|
|
<p className="font-geist text-[0.625rem] leading-relaxed text-m-faint">
|
|
{t('dawarich.serverVersion', { version: S.capabilities.serverVersion })}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
{S.connected && (
|
|
<div className="mt-3">
|
|
<MSetButton variant="danger" onClick={S.disconnect} disabled={S.saving}>
|
|
<Unplug size={14} /> {t('dawarich.disconnect')}
|
|
</MSetButton>
|
|
</div>
|
|
)}
|
|
</MSetCard>
|
|
)
|
|
}
|