pipecountapp-dev / frontend /src /components /SettingsPanel.tsx
Khunndev
Cursor
Add debug mode to show confidence scores inside detection circles.
6544822
Raw History Blame Contribute Delete
7.17 kB
import { RefreshCw } from 'lucide-react'
import { reloadAppForUpdate } from '../lib/appUpdate'
import { t } from '../lib/i18n'
import type { InferenceMode, Lang } from '../lib/types'
interface Props {
lang: Lang
groupCount: number | 'auto'
inferenceMode: InferenceMode
serverAvailable: boolean
useTiling: boolean
filterOutliers: boolean
showConfidenceLabels: boolean
onGroupCount: (value: number | 'auto') => void
onInferenceMode: (mode: InferenceMode) => void
onUseTiling: (value: boolean) => void
onFilterOutliers: (value: boolean) => void
onShowConfidenceLabels: (value: boolean) => void
onRecluster: () => void
}
function Toggle({
checked,
onChange,
label,
description,
}: {
checked: boolean
onChange: (v: boolean) => void
label: string
description?: string
}) {
return (
<button
type="button"
role="switch"
aria-checked={checked}
className="flex min-h-[52px] w-full items-center justify-between gap-3 px-4 text-left transition-colors duration-150 active:bg-[var(--surface-2)]"
onClick={() => onChange(!checked)}
>
<span className="flex flex-col gap-0.5">
<span className="text-[15px] text-[var(--text)]">{label}</span>
{description && (
<span className="text-xs text-[var(--text-faint)]">{description}</span>
)}
</span>
<span
className={`relative h-[31px] w-[51px] shrink-0 rounded-full transition-colors duration-200 ${
checked ? 'bg-[var(--ios-toggle)]' : 'bg-[var(--hairline)]'
}`}
style={{ boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.06)' }}
>
<span
className={`absolute top-[2px] h-[27px] w-[27px] rounded-full bg-white shadow-md transition-all duration-200 ${
checked ? 'left-[22px]' : 'left-[2px]'
}`}
style={{ boxShadow: '0 2px 6px rgba(0,0,0,0.15)' }}
/>
</span>
</button>
)
}
function Separator() {
return <div className="ml-4 h-px bg-[var(--hairline)]" />
}
export function SettingsPanel({
lang,
groupCount,
inferenceMode,
serverAvailable,
useTiling,
filterOutliers,
showConfidenceLabels,
onGroupCount,
onInferenceMode,
onUseTiling,
onFilterOutliers,
onShowConfidenceLabels,
onRecluster,
}: Props) {
return (
<div className="space-y-4">
<section>
<p className="ct-section-label mb-2 px-1">{t(lang, 'inferenceMode')}</p>
<div className="ct-card overflow-hidden p-3">
<div className="flex gap-2">
{(['server', 'local'] as InferenceMode[]).map((mode) => {
const active = inferenceMode === mode
const disabled = mode === 'server' && !serverAvailable
return (
<button
key={mode}
type="button"
disabled={disabled}
className={`flex flex-1 flex-col items-center gap-0.5 rounded-xl px-3 py-2.5 text-center transition-all duration-150 active:scale-[0.98] disabled:opacity-40 ${
active
? 'bg-[var(--brand)] text-white shadow-[var(--shadow-brand)]'
: 'bg-[var(--surface-2)] text-[var(--text-dim)] active:bg-[var(--surface-active)]'
}`}
onClick={() => onInferenceMode(mode)}
>
<span className="text-sm font-semibold">
{mode === 'server' ? t(lang, 'inferenceServer') : t(lang, 'inferenceLocal')}
</span>
<span className={`text-[10px] leading-tight ${active ? 'text-white/90' : 'text-[var(--text-faint)]'}`}>
{mode === 'server' ? t(lang, 'inferenceServerHint') : t(lang, 'inferenceLocalHint')}
</span>
</button>
)
})}
</div>
{!serverAvailable && inferenceMode === 'local' && (
<p className="mt-2 px-1 text-center text-[11px] text-[var(--warning)]">
{t(lang, 'serverUnavailable')}
</p>
)}
</div>
</section>
<section>
<p className="ct-section-label mb-2 px-1">{t(lang, 'groupCount')}</p>
<div className="ct-card overflow-hidden">
<div className="flex flex-wrap gap-2 p-3">
{(['auto', 1, 2, 3, 4, 5, 6] as (number | 'auto')[]).map((n) => {
const active = groupCount === n
return (
<button
key={String(n)}
type="button"
className={`min-h-9 rounded-xl px-4 text-sm font-semibold transition-all duration-150 active:scale-95 ${
active
? 'bg-[var(--brand)] text-white shadow-[var(--shadow-brand)]'
: 'bg-[var(--surface-2)] text-[var(--text-dim)] active:bg-[var(--surface-active)]'
}`}
onClick={() => onGroupCount(n)}
>
{n === 'auto' ? t(lang, 'auto') : n}
</button>
)
})}
<button
type="button"
className="min-h-9 rounded-xl bg-[var(--surface-2)] px-4 text-sm font-semibold text-[var(--text-dim)] transition-all duration-150 active:scale-95 active:bg-[var(--surface-active)]"
onClick={onRecluster}
>
{t(lang, 'apply')}
</button>
</div>
</div>
</section>
<section>
<p className="ct-section-label mb-2 px-1">{t(lang, 'settings')}</p>
<div className="ct-card overflow-hidden">
<Toggle
checked={useTiling}
onChange={onUseTiling}
label={t(lang, 'highAccuracy')}
/>
<Separator />
<Toggle
checked={filterOutliers}
onChange={onFilterOutliers}
label={t(lang, 'filterOutliers')}
/>
</div>
</section>
<section>
<p className="ct-section-label mb-2 px-1">{t(lang, 'debugSection')}</p>
<div className="ct-card overflow-hidden">
<Toggle
checked={showConfidenceLabels}
onChange={onShowConfidenceLabels}
label={t(lang, 'showConfidenceLabels')}
description={t(lang, 'showConfidenceLabelsHint')}
/>
</div>
</section>
<section>
<p className="ct-section-label mb-2 px-1">{t(lang, 'updateApp')}</p>
<div className="ct-card overflow-hidden p-3">
<button
type="button"
className="flex w-full items-center justify-center gap-2 rounded-xl border border-[var(--border)] bg-[var(--surface-2)] px-4 py-3 text-sm font-semibold text-[var(--text)] transition-all active:scale-[0.98] active:bg-[var(--surface-active)]"
onClick={reloadAppForUpdate}
>
<RefreshCw size={16} />
{t(lang, 'updateApp')}
</button>
<p className="mt-2 px-1 text-center text-[11px] text-[var(--text-faint)]">
{t(lang, 'updateAppHint')}
</p>
</div>
</section>
</div>
)
}