diff --git a/src/annotationForm/AnnotationFormManifestNetwork.js b/src/annotationForm/AnnotationFormManifestNetwork.js index 9ece368320edb09dfb81e64852bcba0001bcc72f..03afe4081b4162e991426f310412ca840cf82026 100644 --- a/src/annotationForm/AnnotationFormManifestNetwork.js +++ b/src/annotationForm/AnnotationFormManifestNetwork.js @@ -3,25 +3,10 @@ import { Grid, Paper, TextField, Typography, Button, Link, } from '@mui/material'; import PropTypes from 'prop-types'; +import { isValidUrl } from '../utils'; /** Form part for edit annotation content and body */ function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) { - const isValidUrl = (string) => { - if (string === '') { - return true; - } - try { - new URL(string); - return true; - } catch (_) { - return false; - } - }; - - const onChangeManifestNetworkInput = (event) => { - updateManifestNetwork(event.target.value.trim()); - }; - return ( <Paper style={{ padding: '5px' }}> <Typography variant="overline"> @@ -30,22 +15,19 @@ function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) { <Grid> <TextField value={manifestNetwork} - onChange={onChangeManifestNetworkInput} + onChange={(event) => updateManifestNetwork(event.target.value.trim())} label="Manifest URL" type="url" /> { - isValidUrl(manifestNetwork) && ( + isValidUrl(manifestNetwork) ? ( <Link href={manifestNetwork} target="_blank" > {manifestNetwork} </Link> - ) - } - { - !isValidUrl(manifestNetwork) && ( + ) : ( <Typography variant="caption"> Not a valid URL </Typography> diff --git a/src/utils.js b/src/utils.js index b894d0b99bab74bf9fc5172676599ed7debeb879..f30b3dafd1afc7f8ef6194fb9ba2bcd1d0e8aeef 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,3 +26,15 @@ export function secondsToHMSarray(secs) { seconds: secs % 60, }; } + +export const isValidUrl = (string) => { + if (string === '') { + return true; + } + try { + new URL(string); + return true; + } catch (_) { + return false; + } +};