From 36b44a51e02312931de9e81d2fc00785581a8e0b Mon Sep 17 00:00:00 2001 From: vwh Date: Mon, 23 Sep 2024 01:08:02 +0300 Subject: [PATCH] refactor: refactoring the code --- src/App.tsx | 13 ++++----- src/components/database/table-data.tsx | 4 +-- src/components/database/upper-section.tsx | 10 +++---- src/components/dropzone.tsx | 34 ++++++++++++----------- src/components/stats-message.tsx | 9 +++--- src/lib/sqlite-type-check.ts | 16 +++++------ src/lib/sqlite.ts | 9 ++++-- src/main.tsx | 2 +- 8 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index cd87c2d..3a3f232 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,9 @@ import ProxyMessage from "./components/landing/proxy-message"; import Footer from "./components/landing/footer"; import Features from "./components/landing/features"; +const REGEX_URL = + /^(https?:\/\/(?:www\.)?[a-zA-Z0-9-]{1,256}\.[a-zA-Z]{2,6}(?:\/[^\s]*)?)$/i; + function App() { const { db: isDatabaseLoaded, @@ -25,11 +28,7 @@ function App() { const fetchDatabase = useCallback( async (url: string, useProxy = false) => { - const isGoodURL = - /^(https?:\/\/(?:www\.)?[a-zA-Z0-9-]{1,256}\.[a-zA-Z]{2,6}(?:\/[^\s]*)?)$/i.test( - url - ); - if (!isGoodURL) { + if (!REGEX_URL.test(url)) { setFetchError("Invalid URL"); return; } @@ -113,7 +112,7 @@ function App() { } }, [urlToFetch, fetchDatabase]); - const renderContent = () => { + const Content = () => { if (isLoading || isFetching) { return ( @@ -143,7 +142,7 @@ function App() { > {!isDatabaseLoaded && } - {renderContent()} + {Content()} {!isDatabaseLoaded && ( <>