From 0457c91ede9b44acdb74588a50296c68803e27fb Mon Sep 17 00:00:00 2001 From: ajnart Date: Fri, 27 May 2022 13:14:09 +0200 Subject: [PATCH] :children_crossing: Improve add service autofill capabilities --- src/components/AppShelf/AddAppShelfItem.tsx | 76 +++++++++++++++++---- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/src/components/AppShelf/AddAppShelfItem.tsx b/src/components/AppShelf/AddAppShelfItem.tsx index 2ac5805f2..b4734734a 100644 --- a/src/components/AppShelf/AddAppShelfItem.tsx +++ b/src/components/AppShelf/AddAppShelfItem.tsx @@ -10,6 +10,8 @@ import { ActionIcon, Tooltip, Title, + Anchor, + Text, } from '@mantine/core'; import { useForm } from '@mantine/form'; import { useState } from 'react'; @@ -61,6 +63,31 @@ function MatchIcon(name: string, form: any) { return false; } +function MatchService(name: string, form: any) { + const service = ServiceTypeList.find((s) => s === name); + if (service) { + form.setFieldValue('type', service); + } +} + +function MatchPort(name: string, form: any) { + const portmap = [ + { name: 'qBittorrent', value: '8080' }, + { name: 'Sonarr', value: '8989' }, + { name: 'Radarr', value: '7878' }, + { name: 'Lidarr', value: '8686' }, + { name: 'Readarr', value: '8686' }, + { name: 'Deluge', value: '8112' }, + { name: 'Transmission', value: '9091' }, + ]; + // Match name with portmap key + const port = portmap.find((p) => p.name === name); + console.log('port', port); + if (port) { + form.setFieldValue('url', `http://localhost:${port.value}`); + } +} + export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) { const { setOpened } = props; const { config, setConfig } = useConfig(); @@ -145,10 +172,9 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & value={form.values.name} onChange={(event) => { form.setFieldValue('name', event.currentTarget.value); - const match = MatchIcon(event.currentTarget.value, form); - if (match) { - form.setFieldValue('icon', match); - } + MatchIcon(event.currentTarget.value, form); + MatchService(event.currentTarget.value, form); + MatchPort(event.currentTarget.value, form); }} error={form.errors.name && 'Invalid icon url'} /> @@ -166,7 +192,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & {...form.getInputProps('url')} />