From c4841176573ae17f6a68e4db6f87cee15aaf6354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Fri, 13 Jan 2023 02:18:21 +0800 Subject: [PATCH] refactor: simplify code --- components/user/UserSignIn.vue | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/user/UserSignIn.vue b/components/user/UserSignIn.vue index 904992d52..65669a592 100644 --- a/components/user/UserSignIn.vue +++ b/components/user/UserSignIn.vue @@ -72,17 +72,18 @@ function isValidUrl(str: string) { } async function handleInput() { - if (server.startsWith('https://')) - server = server.replace('https://', '') + const input = server.trim() + if (input.startsWith('https://')) + server = input.replace('https://', '') - if (server?.length) + if (input.length) displayError = false if ( - isValidUrl(`https://${server.trim()}`) - && server.trim().match(/^[a-z0-9-]+(\.[a-z0-9-]+)+(:[0-9]+)?$/i) + isValidUrl(`https://${input}`) + && input.match(/^[a-z0-9-]+(\.[a-z0-9-]+)+(:[0-9]+)?$/i) // Do not hide the autocomplete if a result has an exact substring match on the input - && !filteredServers.some(s => s.includes(server.trim())) + && !filteredServers.some(s => s.includes(input)) ) autocompleteShow = false else