From bc75d810c4cfbfa1b93e6265664a9bec3066ec2f Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 19 Jun 2025 17:47:31 +0800 Subject: [PATCH] feat: choose time --- .../time-picker/header.tsx | 9 +++++-- .../time-picker/index.tsx | 6 +++-- .../base/date-and-time-picker/types.ts | 2 ++ .../auto-update-setting/config.ts | 2 +- .../auto-update-setting/index.tsx | 24 ++++++++++++++++++- web/i18n/en-US/plugin.ts | 1 + web/i18n/zh-Hans/plugin.ts | 1 + 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/web/app/components/base/date-and-time-picker/time-picker/header.tsx b/web/app/components/base/date-and-time-picker/time-picker/header.tsx index 3d85b2ea40..dc6b56f744 100644 --- a/web/app/components/base/date-and-time-picker/time-picker/header.tsx +++ b/web/app/components/base/date-and-time-picker/time-picker/header.tsx @@ -1,13 +1,18 @@ import React from 'react' import { useTranslation } from 'react-i18next' -const Header = () => { +type Props = { + title?: string +} +const Header = ({ + title, +}: Props) => { const { t } = useTranslation() return (
- {t('time.title.pickTime')} + {title || t('time.title.pickTime')}
) diff --git a/web/app/components/base/date-and-time-picker/time-picker/index.tsx b/web/app/components/base/date-and-time-picker/time-picker/index.tsx index a5e666d631..b21c9f9795 100644 --- a/web/app/components/base/date-and-time-picker/time-picker/index.tsx +++ b/web/app/components/base/date-and-time-picker/time-picker/index.tsx @@ -20,6 +20,8 @@ const TimePicker = ({ onChange, onClear, renderTrigger, + title, + popupClassName, }: TimePickerProps) => { const { t } = useTranslation() const [isOpen, setIsOpen] = useState(false) @@ -142,10 +144,10 @@ const TimePicker = ({ )} - +
{/* Header */} -
+
{/* Time Options */} void onClear: () => void renderTrigger?: () => React.ReactNode + title?: string + popupClassName?: string } export type TimePickerFooterProps = { diff --git a/web/app/components/plugins/reference-setting-modal/auto-update-setting/config.ts b/web/app/components/plugins/reference-setting-modal/auto-update-setting/config.ts index 084dfc9731..2144293762 100644 --- a/web/app/components/plugins/reference-setting-modal/auto-update-setting/config.ts +++ b/web/app/components/plugins/reference-setting-modal/auto-update-setting/config.ts @@ -1,7 +1,7 @@ import type { AutoUpdateConfig } from './types' import { AUTO_UPDATE_MODE, AUTO_UPDATE_STRATEGY } from './types' export const defaultValue: AutoUpdateConfig = { - strategy_setting: AUTO_UPDATE_STRATEGY.disabled, + strategy_setting: AUTO_UPDATE_STRATEGY.fixOnly, // For test upgrade_time_of_day: 0, upgrade_mode: AUTO_UPDATE_MODE.update_all, exclude_plugins: [], diff --git a/web/app/components/plugins/reference-setting-modal/auto-update-setting/index.tsx b/web/app/components/plugins/reference-setting-modal/auto-update-setting/index.tsx index 71cda8814d..66eb136913 100644 --- a/web/app/components/plugins/reference-setting-modal/auto-update-setting/index.tsx +++ b/web/app/components/plugins/reference-setting-modal/auto-update-setting/index.tsx @@ -5,9 +5,24 @@ import { AUTO_UPDATE_STRATEGY, type AutoUpdateConfig } from './types' import Label from '../label' import StrategyPicker from './strategy-picker' import { useTranslation } from 'react-i18next' +import TimePicker from '@/app/components/base/date-and-time-picker/time-picker' +import type { Dayjs } from 'dayjs' +import dayjs from 'dayjs' const i18nPrefix = 'plugin.autoUpdate' +const timeOfDayToDayjs = (timeOfDay: number): Dayjs => { + const hours = Math.floor(timeOfDay / 3600) + const minutes = (timeOfDay - hours * 3600) / 60 + const res = dayjs().startOf('day').hour(hours).minute(minutes) + return res +} + +const dayjsToTimeOfDay = (date?: Dayjs): number => { + if(!date) return 0 + return date.hour() * 3600 + date.minute() * 60 +} + type Props = { payload: AutoUpdateConfig onChange: (payload: AutoUpdateConfig) => void @@ -18,7 +33,7 @@ const AutoUpdateSetting: FC = ({ onChange, }) => { const { t } = useTranslation() - const { strategy_setting } = payload + const { strategy_setting, upgrade_time_of_day } = payload const strategyDescription = useMemo(() => { switch (strategy_setting) { case AUTO_UPDATE_STRATEGY.fixOnly: @@ -53,6 +68,13 @@ const AutoUpdateSetting: FC = ({ <>