@@ -14,9 +14,10 @@ import {
14
14
Text ,
15
15
} from '@mantine/core' ;
16
16
import { useForm } from '@mantine/form' ;
17
- import { useState } from 'react' ;
17
+ import { useEffect , useState } from 'react' ;
18
18
import { IconApps as Apps } from '@tabler/icons' ;
19
19
import { v4 as uuidv4 } from 'uuid' ;
20
+ import { useDebouncedValue } from '@mantine/hooks' ;
20
21
import { useConfig } from '../../tools/state' ;
21
22
import { ServiceTypeList } from '../../tools/types' ;
22
23
@@ -64,24 +65,24 @@ function MatchIcon(name: string, form: any) {
64
65
}
65
66
66
67
function MatchService ( name : string , form : any ) {
67
- const service = ServiceTypeList . find ( ( s ) => s === name ) ;
68
+ const service = ServiceTypeList . find ( ( s ) => s . toLowerCase ( ) === name . toLowerCase ( ) ) ;
68
69
if ( service ) {
69
70
form . setFieldValue ( 'type' , service ) ;
70
71
}
71
72
}
72
73
73
74
function MatchPort ( name : string , form : any ) {
74
75
const portmap = [
75
- { name : 'qBittorrent ' , value : '8080' } ,
76
- { name : 'Sonarr ' , value : '8989' } ,
77
- { name : 'Radarr ' , value : '7878' } ,
78
- { name : 'Lidarr ' , value : '8686' } ,
79
- { name : 'Readarr ' , value : '8686' } ,
80
- { name : 'Deluge ' , value : '8112' } ,
81
- { name : 'Transmission ' , value : '9091' } ,
76
+ { name : 'qbittorrent ' , value : '8080' } ,
77
+ { name : 'sonarr ' , value : '8989' } ,
78
+ { name : 'radarr ' , value : '7878' } ,
79
+ { name : 'lidarr ' , value : '8686' } ,
80
+ { name : 'readarr ' , value : '8686' } ,
81
+ { name : 'deluge ' , value : '8112' } ,
82
+ { name : 'transmission ' , value : '9091' } ,
82
83
] ;
83
84
// Match name with portmap key
84
- const port = portmap . find ( ( p ) => p . name === name ) ;
85
+ const port = portmap . find ( ( p ) => p . name === name . toLowerCase ( ) ) ;
85
86
if ( port ) {
86
87
form . setFieldValue ( 'url' , `http://localhost:${ port . value } ` ) ;
87
88
}
@@ -111,6 +112,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
111
112
apiKey : props . apiKey ?? ( undefined as unknown as string ) ,
112
113
username : props . username ?? ( undefined as unknown as string ) ,
113
114
password : props . password ?? ( undefined as unknown as string ) ,
115
+ openedUrl : props . openedUrl ?? ( undefined as unknown as string ) ,
114
116
} ,
115
117
validate : {
116
118
apiKey : ( ) => null ,
@@ -134,6 +136,14 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
134
136
} ,
135
137
} ) ;
136
138
139
+ const [ debounced , cancel ] = useDebouncedValue ( form . values . name , 250 ) ;
140
+ useEffect ( ( ) => {
141
+ if ( form . values . name !== debounced || props . name || props . type ) return ;
142
+ MatchIcon ( form . values . name , form ) ;
143
+ MatchService ( form . values . name , form ) ;
144
+ MatchPort ( form . values . name , form ) ;
145
+ } , [ debounced ] ) ;
146
+
137
147
// Try to set const hostname to new URL(form.values.url).hostname)
138
148
// If it fails, set it to the form.values.url
139
149
let hostname = form . values . url ;
@@ -186,28 +196,26 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
186
196
required
187
197
label = "Service name"
188
198
placeholder = "Plex"
189
- value = { form . values . name }
190
- onChange = { ( event ) => {
191
- form . setFieldValue ( 'name' , event . currentTarget . value ) ;
192
- MatchIcon ( event . currentTarget . value , form ) ;
193
- MatchService ( event . currentTarget . value , form ) ;
194
- MatchPort ( event . currentTarget . value , form ) ;
195
- } }
196
- error = { form . errors . name && 'Invalid icon url' }
199
+ { ...form . getInputProps ( 'name' ) }
197
200
/>
198
201
199
202
< TextInput
200
203
required
201
- label = "Icon url "
202
- placeholder = "https://i.gifer.com/ANPC.gif "
204
+ label = "Icon URL "
205
+ placeholder = "/favicon.svg "
203
206
{ ...form . getInputProps ( 'icon' ) }
204
207
/>
205
208
< TextInput
206
209
required
207
- label = "Service url "
210
+ label = "Service URL "
208
211
placeholder = "http://localhost:7575"
209
212
{ ...form . getInputProps ( 'url' ) }
210
213
/>
214
+ < TextInput
215
+ label = "New tab URL"
216
+ placeholder = "http://sonarr.example.com"
217
+ { ...form . getInputProps ( 'openedUrl' ) }
218
+ />
211
219
< Select
212
220
label = "Service type"
213
221
defaultValue = "Other"
@@ -292,12 +300,12 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
292
300
/>
293
301
</ >
294
302
) }
295
- { form . values . type === 'Deluge' && (
303
+ { ( form . values . type === 'Deluge' || form . values . type === 'Transmission' ) && (
296
304
< >
297
305
< TextInput
298
306
required
299
307
label = "Password"
300
- placeholder = "deluge "
308
+ placeholder = "password "
301
309
value = { form . values . password }
302
310
onChange = { ( event ) => {
303
311
form . setFieldValue ( 'password' , event . currentTarget . value ) ;
0 commit comments