feat: choose time

This commit is contained in:
Joel 2025-06-19 17:47:31 +08:00
parent dc5e974a78
commit bc75d810c4
7 changed files with 39 additions and 6 deletions

View File

@ -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 (
<div className='flex flex-col border-b-[0.5px] border-divider-regular'>
<div className='system-md-semibold flex items-center px-2 py-1.5 text-text-primary'>
{t('time.title.pickTime')}
{title || t('time.title.pickTime')}
</div>
</div>
)

View File

@ -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 = ({
</div>
)}
</PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-50'>
<PortalToFollowElemContent className={cn('z-50', popupClassName)}>
<div className='mt-1 w-[252px] rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadow-lg shadow-shadow-shadow-5'>
{/* Header */}
<Header />
<Header title={title} />
{/* Time Options */}
<Options

View File

@ -54,6 +54,8 @@ export type TimePickerProps = {
onChange: (date: Dayjs | undefined) => void
onClear: () => void
renderTrigger?: () => React.ReactNode
title?: string
popupClassName?: string
}
export type TimePickerFooterProps = {

View File

@ -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: [],

View File

@ -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<Props> = ({
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<Props> = ({
<>
<div className='flex items-center justify-between'>
<Label label={t(`${i18nPrefix}.updateTime`)} />
<TimePicker
value={timeOfDayToDayjs(upgrade_time_of_day)}
onChange={v => handleChange('upgrade_time_of_day')(dayjsToTimeOfDay(v))}
onClear={() => handleChange('upgrade_time_of_day')(0)}
popupClassName='z-[99]'
title={t(`${i18nPrefix}.updateTime`)}
/>
</div>
<div className='flex items-center'>
<Label label={t(`${i18nPrefix}.specifyPluginsToUpdate`)} />

View File

@ -133,6 +133,7 @@ const translation = {
selectedDescription: 'Always update to latest version',
},
},
updateTimeTitle: 'Update time',
},
pluginInfoModal: {
title: 'Plugin info',

View File

@ -133,6 +133,7 @@ const translation = {
selectedDescription: '始终更新到最新版本',
},
},
updateTimeTitle: '更新时间',
},
pluginInfoModal: {
title: '插件信息',