cc-haha/desktop/src/components/tasks/DayOfWeekPicker.tsx
程序员阿江(Relakkes) 8888e1c3fb chore: comprehensive code review fixes — security, perf, leaks, quality, docs
- security: XSS sanitization with DOMPurify in Markdown/Mermaid/PermissionDialog;
  path whitelist in filesystem API; fake keys in test/config files
- perf: fine-grained Zustand selectors in Sidebar/StatusBar/ContentRouter;
  50ms throttle on streaming deltas; React.memo + useMemo in MessageList;
  useRef for frequent keyboard shortcut state; AbortController 30s timeout
- leaks: WS session TTL timers (5-min cleanup on close); batch splice for
  sdkMessages/stderrLines; folderPath validation in cronScheduler
- quality: optimistic update rollback in settingsStore; error state in
  providerStore/teamStore; i18n for all hardcoded English strings
- docs: desktop architecture and features docs updated; VitePress nav fixed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 22:27:17 +08:00

58 lines
1.5 KiB
TypeScript

import { useTranslation } from '../../i18n'
type Props = {
selected: number[]
onChange: (days: number[]) => void
}
// Display order: Mon(1) → Sun(0), matching Chinese convention
const DAY_ORDER = [1, 2, 3, 4, 5, 6, 0]
const DAY_KEYS = [
'newTask.daySun',
'newTask.dayMon',
'newTask.dayTue',
'newTask.dayWed',
'newTask.dayThu',
'newTask.dayFri',
'newTask.daySat',
] as const
export function DayOfWeekPicker({ selected, onChange }: Props) {
const t = useTranslation()
const toggle = (day: number) => {
if (selected.includes(day)) {
// Don't allow deselecting the last day
if (selected.length <= 1) return
onChange(selected.filter((d) => d !== day))
} else {
onChange([...selected, day])
}
}
return (
<div className="flex gap-1.5">
{DAY_ORDER.map((day) => {
const isActive = selected.includes(day)
return (
<button
key={day}
type="button"
onClick={() => toggle(day)}
className={`
w-8 h-8 rounded-full text-xs font-medium transition-colors
${isActive
? 'bg-[var(--color-surface-selected)] text-[var(--color-text-primary)] border border-[var(--color-border-focus)]'
: 'bg-[var(--color-surface)] text-[var(--color-text-tertiary)] border border-[var(--color-border)] hover:bg-[var(--color-surface-hover)]'
}
`}
>
{t(DAY_KEYS[day]!)}
</button>
)
})}
</div>
)
}