Skip to content

Commit

Permalink
chore: refactor lib
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspang committed Aug 2, 2023
1 parent 76c2e7d commit dc480f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions constants/regex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const YOUTUBE_REGEX = /(?<=\d\/|\.be\/|v[=\/])([\w\-]{11,})|^([\w\-]{11})$/;
9 changes: 9 additions & 0 deletions lib/retrieveYoutubeId.ts
Original file line number Diff line number Diff line change
@@ -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 "";
}
12 changes: 2 additions & 10 deletions pages/project/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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" }),
Expand Down

0 comments on commit dc480f3

Please sign in to comment.