From 3f38bbe412caafc056c800cb25422125b228b532 Mon Sep 17 00:00:00 2001 From: marcuspang Date: Wed, 2 Aug 2023 22:51:34 +0200 Subject: [PATCH] chore: refactor lib --- constants/regex.ts | 2 ++ lib/retrieveYoutubeId.ts | 9 +++++++++ pages/project/create/index.tsx | 12 ++---------- 3 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 constants/regex.ts create mode 100644 lib/retrieveYoutubeId.ts diff --git a/constants/regex.ts b/constants/regex.ts new file mode 100644 index 0000000..4cef692 --- /dev/null +++ b/constants/regex.ts @@ -0,0 +1,2 @@ + +export const YOUTUBE_REGEX = /(?<=\d\/|\.be\/|v[=\/])([\w\-]{11,})|^([\w\-]{11})$/; diff --git a/lib/retrieveYoutubeId.ts b/lib/retrieveYoutubeId.ts new file mode 100644 index 0000000..6dc40e9 --- /dev/null +++ b/lib/retrieveYoutubeId.ts @@ -0,0 +1,9 @@ +import { YOUTUBE_REGEX } from "@/constants/regex"; + +export function retrieveYoutubeId(url: string) { + const match = YOUTUBE_REGEX.exec(url); + if (match !== null) { + return match[1]; + } + return ""; +} diff --git a/pages/project/create/index.tsx b/pages/project/create/index.tsx index 7ab034f..5238fcd 100644 --- a/pages/project/create/index.tsx +++ b/pages/project/create/index.tsx @@ -55,6 +55,8 @@ import { useRouter } from "next/router"; import { useContext, useEffect } from "react"; import { AuthContext } from "@/components/AuthProvider"; import { isAddress } from "viem"; +import { retrieveYoutubeId } from "../../../lib/retrieveYoutubeId"; +import { YOUTUBE_REGEX } from "../../../constants/regex"; async function createProject( idToken: string, @@ -98,16 +100,6 @@ async function getCheckoutLink( return ""; } -function retrieveYoutubeId(url: string) { - const match = YOUTUBE_REGEX.exec(url); - if (match !== null) { - return match[1]; - } - return ""; -} - -const YOUTUBE_REGEX = /(?<=\d\/|\.be\/|v[=\/])([\w\-]{11,})|^([\w\-]{11})$/; - const formSchema = z.object({ title: z.string().min(1, { message: "Title is required" }), description: z.string().min(1, { message: "Description is required" }),