feat: choose auto update description and i18n

This commit is contained in:
Joel 2025-06-19 16:27:17 +08:00
parent baff25c160
commit dc5e974a78
3 changed files with 53 additions and 9 deletions

View File

@ -1,9 +1,12 @@
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import type { AutoUpdateConfig } from './types'
import React, { useCallback, useMemo } from 'react'
import { AUTO_UPDATE_STRATEGY, type AutoUpdateConfig } from './types'
import Label from '../label'
import StrategyPicker from './strategy-picker'
import { useTranslation } from 'react-i18next'
const i18nPrefix = 'plugin.autoUpdate'
type Props = {
payload: AutoUpdateConfig
@ -14,7 +17,18 @@ const AutoUpdateSetting: FC<Props> = ({
payload,
onChange,
}) => {
const { t } = useTranslation()
const { strategy_setting } = payload
const strategyDescription = useMemo(() => {
switch (strategy_setting) {
case AUTO_UPDATE_STRATEGY.fixOnly:
return t(`${i18nPrefix}.strategy.fixOnly.selectedDescription`)
case AUTO_UPDATE_STRATEGY.latest:
return t(`${i18nPrefix}.strategy.latest.selectedDescription`)
default:
return ''
}
}, [strategy_setting, t])
const handleChange = useCallback((key: keyof AutoUpdateConfig) => {
return (value: AutoUpdateConfig[keyof AutoUpdateConfig]) => {
onChange({
@ -32,15 +46,19 @@ const AutoUpdateSetting: FC<Props> = ({
<div className='space-y-4'>
<div className='flex items-center justify-between'>
<Label label='Automatic updates' />
<Label label={t(`${i18nPrefix}.automaticUpdates`)} description={strategyDescription} />
<StrategyPicker value={strategy_setting} onChange={handleChange('strategy_setting')} />
</div>
<div className='flex items-center justify-between'>
<Label label='Update time' />
</div>
<div className='flex items-center'>
<Label label='Specify plugins to update' />
</div>
{strategy_setting !== AUTO_UPDATE_STRATEGY.disabled && (
<>
<div className='flex items-center justify-between'>
<Label label={t(`${i18nPrefix}.updateTime`)} />
</div>
<div className='flex items-center'>
<Label label={t(`${i18nPrefix}.specifyPluginsToUpdate`)} />
</div>
</>
)}
</div>
</div>
)

View File

@ -114,6 +114,9 @@ const translation = {
noone: 'No one',
},
autoUpdate: {
automaticUpdates: 'Automatic updates',
updateTime: 'Update time',
specifyPluginsToUpdate: 'Specify plugins to update',
strategy: {
disabled: {
name: 'Disabled',
@ -122,10 +125,12 @@ const translation = {
fixOnly: {
name: 'Fix Only',
description: 'Auto-update for patch versions only (e.g., 1.0.1 → 1.0.2). Minor version changes won\'t trigger updates.',
selectedDescription: 'Auto-update for patch versions only',
},
latest: {
name: 'Latest',
description: 'Always update to latest version',
selectedDescription: 'Always update to latest version',
},
},
},

View File

@ -113,6 +113,27 @@ const translation = {
admins: '管理员',
noone: '无人',
},
autoUpdate: {
automaticUpdates: '自动更新',
updateTime: '更新时间',
specifyPluginsToUpdate: '指定要更新的插件',
strategy: {
disabled: {
name: '禁用',
description: '插件将不会自动更新',
},
fixOnly: {
name: '仅修复',
description: '仅自动更新补丁版本例如1.0.1 → 1.0.2)。次要版本更改不会触发更新。',
selectedDescription: '仅自动更新补丁版本',
},
latest: {
name: '最新',
description: '始终更新到最新版本',
selectedDescription: '始终更新到最新版本',
},
},
},
pluginInfoModal: {
title: '插件信息',
repository: '仓库',