@@ -6,6 +6,12 @@ import {observer} from 'mobx-react-lite'
6
6
import { ScrollView , Text , TouchableOpacity , View } from 'react-native'
7
7
import { useStore } from 'store'
8
8
9
+ export const isValidCustomSearchEngineUrl = ( url : string ) => {
10
+ if ( url . trim ( ) === '' ) return false
11
+ const searchPatternRegex =
12
+ / ^ h t t p s ? : \/ \/ (?: (?: [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] * [ a - z A - Z 0 - 9 ] ) ? \. ) + [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] * [ a - z A - Z 0 - 9 ] ) ? | l o c a l h o s t | \d { 1 , 3 } \. \d { 1 , 3 } \. \d { 1 , 3 } \. \d { 1 , 3 } ) ( : \d + ) ? ( \/ [ ^ \s ? # ] * ) ? \? q = % s $ /
13
+ return searchPatternRegex . test ( url )
14
+ }
9
15
export const General = observer ( ( ) => {
10
16
const store = useStore ( )
11
17
return (
@@ -65,18 +71,28 @@ export const General = observer(() => {
65
71
/>
66
72
{ value === 'custom' && (
67
73
< View className = "flex-1" >
68
- < Input
69
- className = "w-80 text-xs rounded border border-lightBorder dark:border-darkBorder px-1"
70
- inputClassName = {
71
- store . ui . searchEngine !== 'custom'
72
- ? 'opacity-45 dark:text-white'
73
- : ''
74
- }
75
- readOnly = { store . ui . searchEngine !== 'custom' }
76
- value = { store . ui . customSearchUrl }
77
- onChangeText = { e => store . ui . setCustomSearchUrl ( e ) }
78
- placeholder = "https://google.com/search?q=%s"
79
- />
74
+ < View className = "flex-row items-center gap-2" >
75
+ < Input
76
+ className = "w-80 text-xs rounded border border-lightBorder dark:border-darkBorder px-1"
77
+ inputClassName = {
78
+ store . ui . searchEngine !== 'custom'
79
+ ? 'opacity-45 dark:text-white'
80
+ : ''
81
+ }
82
+ readOnly = { store . ui . searchEngine !== 'custom' }
83
+ value = { store . ui . customSearchUrl }
84
+ onChangeText = { e => store . ui . setCustomSearchUrl ( e ) }
85
+ placeholder = "https://google.com/search?q=%s"
86
+ />
87
+ { store . ui . searchEngine === 'custom' &&
88
+ ( isValidCustomSearchEngineUrl (
89
+ store . ui . customSearchUrl ,
90
+ ) ? (
91
+ < View className = "w-2 h-2 rounded-full bg-green-500" />
92
+ ) : (
93
+ < View className = "w-2 h-2 rounded-full bg-red-500" />
94
+ ) ) }
95
+ </ View >
80
96
< Text className = "text-xs text-neutral-500 dark:text-neutral-400 mt-1 ml-1" >
81
97
Use %s in place of the search term
82
98
</ Text >
0 commit comments