Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(task): use lobe-ui ToggleGroup for weekday picker (#21111)

Arvin Xuf5e4847238e5
diff --git a/package.json b/package.json
index f69cc959735..b07d0bc503d 100644
--- a/package.json
+++ b/package.json
@@ -325,7 +325,7 @@
"@lobehub/editor": "^5.0.0",
"@lobehub/icons": "^6.0.0",
"@lobehub/market-sdk": "0.42.0",
- "@lobehub/ui": "^6.0.4",
+ "@lobehub/ui": "^6.3.0",
"@modelcontextprotocol/sdk": "^1.30.0",
"@neondatabase/serverless": "^1.1.0",
"@next/third-parties": "^16.3.0",
diff --git a/src/features/AgentTasks/AgentTaskDetail/scheduler/SchedulerForm.tsx b/src/features/AgentTasks/AgentTaskDetail/scheduler/SchedulerForm.tsx
index debbc39a165..6e47612941e 100644
--- a/src/features/AgentTasks/AgentTaskDetail/scheduler/SchedulerForm.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/scheduler/SchedulerForm.tsx
@@ -3,16 +3,16 @@ import {
Checkbox,
createStaticStyles,
cssVar,
- cx,
Flexbox,
Icon,
InputNumber,
Select,
Text,
+ ToggleGroup,
} from '@lobehub/ui';
import dayjs, { type Dayjs } from 'dayjs';
import { Globe, Hash, SlidersHorizontal } from 'lucide-react';
-import { memo, useCallback, useState } from 'react';
+import { memo, useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -44,39 +44,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
min-width: 0;
`,
- weekdayButton: css`
- cursor: pointer;
-
- display: flex;
- align-items: center;
- justify-content: center;
-
- width: 36px;
- height: 32px;
- border-radius: 6px;
-
- font-size: 12px;
- font-weight: 500;
- color: ${cssVar.colorTextSecondary};
-
- background: transparent;
-
- transition: all 0.15s ease;
-
- &:hover {
- color: ${cssVar.colorText};
- background: ${cssVar.colorFillTertiary};
- }
- `,
- weekdayButtonActive: css`
- color: ${cssVar.colorPrimary};
- background: ${cssVar.colorPrimaryBg};
-
- &:hover {
- color: ${cssVar.colorPrimary};
- background: ${cssVar.colorPrimaryBgHover};
- }
- `,
}));
const DEFAULT_PATTERN = '0 9 * * *';
@@ -108,6 +75,11 @@ interface SchedulerFormProps {
const SchedulerForm = memo<SchedulerFormProps>(({ maxExecutions, onChange, pattern, timezone }) => {
const { t } = useTranslation('chat');
+ const weekdayOptions = useMemo(
+ () => WEEKDAYS.map(({ key, label }) => ({ label: t(label as any), value: String(key) })),
+ [t],
+ );
+
// Local state seeded once from props at mount; never re-synced. Keeps the
// form in user control even if an unrelated detail refresh runs concurrently.
// Parent should `key={taskId}` this component to remount cleanly across tasks.
@@ -203,8 +175,8 @@ const SchedulerForm = memo<SchedulerFormProps>(({ maxExecutions, onChange, patte
emit({ hourlyInterval: next });
};
- const toggleWeekday = (day: number) => {
- const next = weekdays.includes(day) ? weekdays.filter((d) => d !== day) : [...weekdays, day];
+ const handleWeekdaysChange = (values: string[]) => {
+ const next = values.map(Number).sort((a, b) => a - b);
setWeekdays(next);
emit({ weekdays: next });
};
@@ -297,20 +269,13 @@ const SchedulerForm = memo<SchedulerFormProps>(({ maxExecutions, onChange, patte
{scheduleType === 'weekly' && (
<Flexbox gap={6}>
<Text className={styles.fieldLabel}>{t('taskSchedule.weekday')}</Text>
- <Flexbox horizontal gap={6}>
- {WEEKDAYS.map(({ key, label }) => (
- <div
- key={key}
- className={cx(
- styles.weekdayButton,
- weekdays.includes(key) && styles.weekdayButtonActive,
- )}
- onClick={() => toggleWeekday(key)}
- >
- {t(label as any)}
- </div>
- ))}
- </Flexbox>
+ <ToggleGroup
+ multiple
+ options={weekdayOptions}
+ size="small"
+ value={weekdays.map(String)}
+ onChange={handleWeekdaysChange}
+ />
</Flexbox>
)}