diff --git a/bun.lockb b/bun.lockb index 67d3141..9bb0c7e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 0da3e39..e62f2a9 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "contentlayer": "^0.3.4", "cz-customizable": "^7.0.0", "date-fns": "^2.30.0", + "fast-shuffle": "^6.0.1", "framer-motion": "^10.16.4", "husky": "^8.0.3", "lint-staged": "^15.0.2", diff --git a/src/components/Profile/ProfileCardList/ProfileCardList.tsx b/src/components/Profile/ProfileCardList/ProfileCardList.tsx index 062ced0..b06b8dc 100644 --- a/src/components/Profile/ProfileCardList/ProfileCardList.tsx +++ b/src/components/Profile/ProfileCardList/ProfileCardList.tsx @@ -4,17 +4,18 @@ import SpacingDivider from "@/components/Common/SpacingDivider/SpacingDivider"; import TitleText from "@/components/Common/TitleText/TitleText"; import SquareBox from "@/components/Ui/SquareBox/SquareBox"; import { cn, generateColor } from "@/utils"; -import { profileHelperService } from "@/utils/profileHelper"; +import { checkIsFoundTag, profileHelperService } from "@/utils/profileHelper"; import { Profile } from "contentlayer/generated"; import Image from "next/image"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; +import { IoPeople } from "react-icons/io5"; type TPropsProfileCardList = { profiles: Profile[]; }; -const Tag = ({ tag }: { tag: string }) => { +const Tag = ({ tag, searchTag }: { tag: string; searchTag: string }) => { const searchParams = useSearchParams(); const router = useRouter(); @@ -24,8 +25,10 @@ const Tag = ({ tag }: { tag: string }) => { return ( { <>
{uniqueTags.map((tag) => ( - + ))}
+ + + Total Profiles :{filteredProfiles.length} + +
@@ -96,8 +104,8 @@ const ProfileCardList = ({ profiles }: TPropsProfileCardList) => {
- {profile.tags?.slice(0, 8)?.map((tag) => ( - + {profile.tags?.map((tag) => ( + ))}
{ const uniqueTags: string[] = []; @@ -23,45 +24,15 @@ export const profileHelperService = ( profile.tags = profileTags; tags.push(profileTags); - if (!!searchTag) { - let isAlreayIncludedInProfile = false; - profileTags.forEach((pTag) => { - const profileTag = pTag.toLowerCase(); - const sTagLowerCase = searchTag.toLowerCase(); + let isAlreadyIncludedInProfile = false; - if (isAlreayIncludedInProfile) return; + if (!!searchTag && !isAlreadyIncludedInProfile) { + profileTags.forEach((pTag) => { + if (isAlreadyIncludedInProfile) return; - if (profileTag === sTagLowerCase) { - // exact match - foundProfiles.push(profile); - isAlreayIncludedInProfile = true; - } else if ( - profileTag === sTagLowerCase + "js" || - profileTag === sTagLowerCase + ".js" - ) { - // try add js or .js extension to search tag - foundProfiles.push(profile); - isAlreayIncludedInProfile = true; - } else if ( - profileTag === sTagLowerCase.replace(/\.js$/, "") || - profileTag === sTagLowerCase.replace(/js$/, "") - ) { - // try remove js or .js extension from search tag + if (checkIsFoundTag(pTag, searchTag)) { foundProfiles.push(profile); - isAlreayIncludedInProfile = true; - } else if ( - profileTag + "js" === sTagLowerCase || - profileTag + ".js" === sTagLowerCase - ) { - foundProfiles.push(profile); - isAlreayIncludedInProfile = true; - } else if ( - profileTag === sTagLowerCase.replace(/\.js$/, "") + "js" || - profileTag === sTagLowerCase.replace(/js$/, "") + ".js" - ) { - // try swap .js and js extension - foundProfiles.push(profile); - isAlreayIncludedInProfile = true; + isAlreadyIncludedInProfile = true; } }); } @@ -70,7 +41,37 @@ export const profileHelperService = ( const uniqueTags = getUniqueTags(tags.flat(1)); return { - foundProfiles: !!searchTag ? foundProfiles : profiles, + foundProfiles: shuffle(!!searchTag ? foundProfiles : profiles), uniqueTags, }; }; + +export const checkIsFoundTag = (profileTag: string, searchTag: string) => { + const sTagLowerCase = searchTag.toLowerCase(); + const pTagLowerCase = profileTag.toLowerCase(); + + const isExactMatch = pTagLowerCase === searchTag; + if (isExactMatch) return true; + + const isWithJsOrDotJSMatch = + pTagLowerCase === sTagLowerCase + "js" || + pTagLowerCase === sTagLowerCase + ".js"; + if (isWithJsOrDotJSMatch) return true; + + const isRemoveJsOrDotJsExtensionMatch = + pTagLowerCase === sTagLowerCase.replace(/\.js$/, "") || + pTagLowerCase === sTagLowerCase.replace(/js$/, ""); + if (isRemoveJsOrDotJsExtensionMatch) return true; + + const isAddJsOrDotJsToProfileTagMatch = + pTagLowerCase + "js" === sTagLowerCase || + pTagLowerCase + ".js" === sTagLowerCase; + if (isAddJsOrDotJsToProfileTagMatch) return true; + + const isTrySwapDotJsAndJsExtMatch = + pTagLowerCase === sTagLowerCase.replace(/\.js$/, "") + "js" || + pTagLowerCase === sTagLowerCase.replace(/js$/, "") + ".js"; + if (isTrySwapDotJsAndJsExtMatch) return true; + + return false; +};