-
-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support Change Service on Translate Card
- Loading branch information
Showing
3 changed files
with
182 additions
and
93 deletions.
There are no files selected for viewing
123 changes: 67 additions & 56 deletions
123
src/window/Config/pages/Service/Translate/ServiceItem/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,87 @@ | ||
import { RxDragHandleHorizontal } from 'react-icons/rx'; | ||
import { Spacer, Button } from '@nextui-org/react'; | ||
import { Spacer, Button, Switch } from '@nextui-org/react'; | ||
import { MdDeleteOutline } from 'react-icons/md'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { BiSolidEdit } from 'react-icons/bi'; | ||
import React from 'react'; | ||
|
||
import * as buildinServices from '../../../../../../services/translate'; | ||
import { useConfig } from '../../../../../../hooks'; | ||
|
||
export default function ServiceItem(props) { | ||
const { name, deleteService, setConfigName, onConfigOpen, pluginList, ...drag } = props; | ||
const serviceType = name.startsWith('[plugin]') ? 'plugin' : 'buildin'; | ||
const { t } = useTranslation(); | ||
const [serviceConfig, setServiceConfig] = useConfig(name, {}); | ||
|
||
return serviceType === 'plugin' && !(name in pluginList) ? ( | ||
<></> | ||
) : ( | ||
<div className='bg-content2 rounded-md px-[10px] py-[20px] flex justify-between'> | ||
<div className='flex'> | ||
<div | ||
{...drag} | ||
className='text-2xl my-auto' | ||
> | ||
<RxDragHandleHorizontal /> | ||
</div> | ||
serviceConfig !== null && ( | ||
<div className='bg-content2 rounded-md px-[10px] py-[20px] flex justify-between'> | ||
<div className='flex'> | ||
<div | ||
{...drag} | ||
className='text-2xl my-auto' | ||
> | ||
<RxDragHandleHorizontal /> | ||
</div> | ||
|
||
<Spacer x={2} /> | ||
{serviceType === 'buildin' && ( | ||
<> | ||
<img | ||
src={`${buildinServices[name].info.icon}`} | ||
className='h-[24px] w-[24px] my-auto' | ||
/> | ||
<Spacer x={2} /> | ||
<h2 className='my-auto'>{t(`services.translate.${name}.title`)}</h2> | ||
</> | ||
)} | ||
{serviceType === 'plugin' && ( | ||
<> | ||
<img | ||
src={pluginList[name].icon} | ||
className='h-[24px] w-[24px] my-auto' | ||
/> | ||
<Spacer x={2} /> | ||
<h2 className='my-auto'>{`${pluginList[name].display} [${t('common.plugin')}]`}</h2> | ||
</> | ||
)} | ||
</div> | ||
<div className='flex'> | ||
<Button | ||
isIconOnly | ||
size='sm' | ||
variant='light' | ||
onPress={() => { | ||
setConfigName(name); | ||
onConfigOpen(); | ||
}} | ||
> | ||
<BiSolidEdit className='text-2xl' /> | ||
</Button> | ||
<Spacer x={2} /> | ||
<Button | ||
isIconOnly | ||
size='sm' | ||
variant='light' | ||
color='danger' | ||
onClick={() => { | ||
deleteService(name); | ||
}} | ||
> | ||
<MdDeleteOutline className='text-2xl' /> | ||
</Button> | ||
<Spacer x={2} /> | ||
{serviceType === 'buildin' && ( | ||
<> | ||
<img | ||
src={`${buildinServices[name].info.icon}`} | ||
className='h-[24px] w-[24px] my-auto' | ||
/> | ||
<Spacer x={2} /> | ||
<h2 className='my-auto'>{t(`services.translate.${name}.title`)}</h2> | ||
</> | ||
)} | ||
{serviceType === 'plugin' && ( | ||
<> | ||
<img | ||
src={pluginList[name].icon} | ||
className='h-[24px] w-[24px] my-auto' | ||
/> | ||
<Spacer x={2} /> | ||
<h2 className='my-auto'>{`${pluginList[name].display} [${t('common.plugin')}]`}</h2> | ||
</> | ||
)} | ||
</div> | ||
<div className='flex'> | ||
<Switch | ||
size='sm' | ||
isSelected={serviceConfig['enable'] ?? true} | ||
onValueChange={(v) => { | ||
setServiceConfig({ ...serviceConfig, enable: v }); | ||
}} | ||
/> | ||
<Button | ||
isIconOnly | ||
size='sm' | ||
variant='light' | ||
onPress={() => { | ||
setConfigName(name); | ||
onConfigOpen(); | ||
}} | ||
> | ||
<BiSolidEdit className='text-2xl' /> | ||
</Button> | ||
<Spacer x={2} /> | ||
<Button | ||
isIconOnly | ||
size='sm' | ||
variant='light' | ||
color='danger' | ||
onClick={() => { | ||
deleteService(name); | ||
}} | ||
> | ||
<MdDeleteOutline className='text-2xl' /> | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.