mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-25 08:35:42 +02:00
refactor: resource meta
This commit is contained in:
@@ -20,6 +20,7 @@ import { replaceChildren } from '../../lib/dom.ts';
|
||||
import { XIcon } from 'lucide-react';
|
||||
import type { PageType } from '../CommandMenu/CommandMenu.tsx';
|
||||
import { renderFlowJSON } from '../../../editor/renderer/renderer.ts';
|
||||
import { getResourceMeta } from '../../lib/roadmap.ts';
|
||||
|
||||
export type ProgressMapProps = {
|
||||
member: TeamMember;
|
||||
@@ -90,22 +91,7 @@ export function MemberProgressModal(props: ProgressMapProps) {
|
||||
}
|
||||
|
||||
async function renderResource(jsonUrl: string) {
|
||||
const { error, response } = await httpGet<PageType[]>(`/pages.json`);
|
||||
if (error || !response) {
|
||||
toast.error(error?.message || 'Resource not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const page = response.find((page) => {
|
||||
if (resourceType === 'roadmap') {
|
||||
return page.url === `/${resourceId}`;
|
||||
} else if (resourceType === 'best-practice') {
|
||||
return page.url === `/best-practices/${resourceId}`;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
const page = await getResourceMeta(resourceType, resourceId);
|
||||
if (!page) {
|
||||
toast.error('Resource not found');
|
||||
return;
|
||||
|
@@ -1,4 +1,7 @@
|
||||
import type { PageType } from '../components/CommandMenu/CommandMenu';
|
||||
import type { MarkdownFileType } from './file';
|
||||
import { httpGet } from './http';
|
||||
import type { ResourceType } from './resource-progress';
|
||||
|
||||
export function resourceTitleFromId(id: string): string {
|
||||
if (id === 'devops') {
|
||||
@@ -150,3 +153,29 @@ export async function getRoadmapFaqsById(roadmapId: string): Promise<string[]> {
|
||||
|
||||
return faqs || [];
|
||||
}
|
||||
|
||||
export async function getResourceMeta(
|
||||
resourceType: ResourceType,
|
||||
resourceId: string,
|
||||
) {
|
||||
const { error, response } = await httpGet<PageType[]>(`/pages.json`);
|
||||
if (error || !response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const page = response.find((page) => {
|
||||
if (resourceType === 'roadmap') {
|
||||
return page.url === `/${resourceId}`;
|
||||
} else if (resourceType === 'best-practice') {
|
||||
return page.url === `/best-practices/${resourceId}`;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!page) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
Reference in New Issue
Block a user