chore: roadmaps array

pull/4053/head
Arik Chakma 1 year ago
parent 33e732edad
commit 5282bef453
  1. 32
      src/helper/get-badge-link.ts

@ -1,22 +1,31 @@
import type { RoadmapOptionProps } from "../components/RoadCard/RoadmapSelect"; import type { RoadmapOptionProps } from '../components/RoadCard/RoadmapSelect';
import type { useAuth } from "../hooks/use-auth"; import type { useAuth } from '../hooks/use-auth';
export type GetBadgeLinkProps = { export type GetBadgeLinkProps = {
user: ReturnType<typeof useAuth>; user: ReturnType<typeof useAuth>;
variant: 'dark' | 'light'; variant: 'dark' | 'light';
badge: 'tall' | 'wide'; badge: 'tall' | 'wide';
roadmaps?: RoadmapOptionProps[] roadmaps?: RoadmapOptionProps[];
}; };
export function getBadgeLink({ user, variant, badge, roadmaps }: GetBadgeLinkProps) { export function getBadgeLink({
const badgeUrl = new URL(`${import.meta.env.PUBLIC_API_URL}/v1-badge/${badge}/${user?.id}`); user,
variant,
badge,
roadmaps,
}: GetBadgeLinkProps) {
const badgeUrl = new URL(
`${import.meta.env.PUBLIC_API_URL}/v1-badge/${badge}/${user?.id}`
);
if (variant) { if (variant) {
badgeUrl.searchParams.set('variant', variant); badgeUrl.searchParams.set('variant', variant);
} }
if (roadmaps && roadmaps?.length > 0) { const isRoadmapArray = roadmaps && Array.isArray(roadmaps) && roadmaps.length;
for (const roadmap of roadmaps) { if (isRoadmapArray) {
badgeUrl.searchParams.append('roadmaps', roadmap.value); badgeUrl.searchParams.set(
} 'roadmaps',
roadmaps.map(({ value }) => value).join(',')
);
} }
const textareaContent = ` const textareaContent = `
<a href="${badgeUrl}"> <a href="${badgeUrl}">
@ -24,8 +33,9 @@ export function getBadgeLink({ user, variant, badge, roadmaps }: GetBadgeLinkPro
</a> </a>
`.trim(); `.trim();
const markdownSnippet = ` const markdownSnippet = `
[![${user?.name}${user?.name && "'s" [![${user?.name}${
} Road Card](${badgeUrl})](${badgeUrl}) user?.name && "'s"
} Road Card](${badgeUrl})](${badgeUrl})
`.trim(); `.trim();
return { return {

Loading…
Cancel
Save