Fix sorting order of roadmaps

pull/7095/head
Kamran Ahmed 2 months ago
parent ae58fa2a2a
commit 298b137a7d
  1. 36
      src/components/Projects/ProjectsPage.tsx
  2. 5
      src/pages/projects/index.astro

@ -81,6 +81,18 @@ export function ProjectsPage(props: ProjectsPageProps) {
(group) => group.id === activeGroup, (group) => group.id === activeGroup,
); );
const requiredSortOrder = [
'Frontend',
'Backend',
'DevOps',
'Full-stack',
'JavaScript',
'Go',
'Python',
'Node.js',
'Java',
];
return ( return (
<div className="border-t bg-gray-100"> <div className="border-t bg-gray-100">
<button <button
@ -122,13 +134,33 @@ export function ProjectsPage(props: ProjectsPageProps) {
selected={activeGroup === ''} selected={activeGroup === ''}
/> />
{roadmapsProjects.map((group) => ( {roadmapsProjects
.sort((a, b) => {
const aIndex = requiredSortOrder.indexOf(a.title);
const bIndex = requiredSortOrder.indexOf(b.title);
if (aIndex === -1 && bIndex === -1) {
return a.title.localeCompare(b.title);
}
if (aIndex === -1) {
return 1;
}
if (bIndex === -1) {
return -1;
}
return aIndex - bIndex;
})
.map((group) => (
<CategoryFilterButton <CategoryFilterButton
key={group.id} key={group.id}
onClick={() => { onClick={() => {
setActiveGroup(group.id); setActiveGroup(group.id);
setIsFilterOpen(false); setIsFilterOpen(false);
document?.getElementById('filter-button')?.scrollIntoView(); document
?.getElementById('filter-button')
?.scrollIntoView();
setVisibleProjects(group.projects); setVisibleProjects(group.projects);
setUrlParams({ g: group.id }); setUrlParams({ g: group.id });
}} }}

@ -11,7 +11,10 @@ const allRoadmapIds = Object.keys(roadmapProjects);
const allRoadmaps = await getRoadmapsByIds(allRoadmapIds); const allRoadmaps = await getRoadmapsByIds(allRoadmapIds);
const enrichedRoadmaps = allRoadmaps.map((roadmap) => { const enrichedRoadmaps = allRoadmaps.map((roadmap) => {
const projects = roadmapProjects[roadmap.id]; const projects = (roadmapProjects[roadmap.id] || []).sort((a, b) => {
return a.frontmatter.sort - b.frontmatter.sort;
});
return { return {
id: roadmap.id, id: roadmap.id,
title: roadmap.frontmatter.briefTitle, title: roadmap.frontmatter.briefTitle,

Loading…
Cancel
Save