mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-25 16:39:02 +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 { XIcon } from 'lucide-react';
|
||||||
import type { PageType } from '../CommandMenu/CommandMenu.tsx';
|
import type { PageType } from '../CommandMenu/CommandMenu.tsx';
|
||||||
import { renderFlowJSON } from '../../../editor/renderer/renderer.ts';
|
import { renderFlowJSON } from '../../../editor/renderer/renderer.ts';
|
||||||
|
import { getResourceMeta } from '../../lib/roadmap.ts';
|
||||||
|
|
||||||
export type ProgressMapProps = {
|
export type ProgressMapProps = {
|
||||||
member: TeamMember;
|
member: TeamMember;
|
||||||
@@ -90,22 +91,7 @@ export function MemberProgressModal(props: ProgressMapProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function renderResource(jsonUrl: string) {
|
async function renderResource(jsonUrl: string) {
|
||||||
const { error, response } = await httpGet<PageType[]>(`/pages.json`);
|
const page = await getResourceMeta(resourceType, resourceId);
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
toast.error('Resource not found');
|
toast.error('Resource not found');
|
||||||
return;
|
return;
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
|
import type { PageType } from '../components/CommandMenu/CommandMenu';
|
||||||
import type { MarkdownFileType } from './file';
|
import type { MarkdownFileType } from './file';
|
||||||
|
import { httpGet } from './http';
|
||||||
|
import type { ResourceType } from './resource-progress';
|
||||||
|
|
||||||
export function resourceTitleFromId(id: string): string {
|
export function resourceTitleFromId(id: string): string {
|
||||||
if (id === 'devops') {
|
if (id === 'devops') {
|
||||||
@@ -150,3 +153,29 @@ export async function getRoadmapFaqsById(roadmapId: string): Promise<string[]> {
|
|||||||
|
|
||||||
return faqs || [];
|
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