String updates
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Stack, TextInput } from '@mantine/core';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
import { HelpModal, WeatherModal } from 'components';
|
||||
import { containsProtocol, useCommonHooks, validURL } from 'hooks';
|
||||
import { useCommonHooks } from 'hooks';
|
||||
import { textInputClasses } from 'styles';
|
||||
|
||||
export default function Search({
|
||||
@@ -27,6 +27,15 @@ export default function Search({
|
||||
const handleKeyPress = (item: any) => {
|
||||
let option = '';
|
||||
let subtext = '';
|
||||
const urlPattern = new RegExp(
|
||||
'^(https?:\\/\\/)?' + // protocol
|
||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
||||
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
||||
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
||||
'(\\#[-a-z\\d_]*)?$',
|
||||
'i',
|
||||
); // fragment locator
|
||||
if (item.target.value.startsWith('/')) {
|
||||
option =
|
||||
item.target.value.substr(1, item.target.value.indexOf(' ') - 1) ||
|
||||
@@ -46,8 +55,9 @@ export default function Search({
|
||||
open(`${providerURL}${subtext}`, '_self');
|
||||
} else if (providerLabel === 'Show weather') {
|
||||
openWeatherModal();
|
||||
} else if (validURL(item.target.value)) {
|
||||
if (containsProtocol(item.target.value)) window.location = item.target.value;
|
||||
} else if (urlPattern.test(item.target.value)) {
|
||||
if (/^(https?:\/\/).*/i.test(item.target.value))
|
||||
window.location = item.target.value;
|
||||
else open(`https://${item.target.value}`, '_self');
|
||||
} else {
|
||||
open(`${providerURL}${subtext}`, '_self');
|
||||
|
||||
Reference in New Issue
Block a user