Skip to content

Commit b7961fb

Browse files
committed
fetch categories from API and update category keys to use lowercase slugs
1 parent 8b1617f commit b7961fb

File tree

2 files changed

+69
-53
lines changed

2 files changed

+69
-53
lines changed

client/src/components/CategoriesDropdown.tsx

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,31 @@ export function CategoriesDropdown({ isMobile, onSelectMobile }: CategoryProps)
1111
const [isCategoriesMenuOpen, setIsCategoriesMenuOpen] = useState(false);
1212
const categoriesMenuRef = useRef<HTMLDivElement>(null);
1313
const { t } = useLanguage();
14+
const [categoryKeys, setCategoryKeys] = useState<string[]>([]);
15+
const [isLoading, setIsLoading] = useState(true);
1416

15-
// Category keys for translation and URL slugs
16-
const categoryKeys = [
17-
"browser-automation",
18-
"cloud-platforms",
19-
"communication",
20-
"databases",
21-
"file-systems",
22-
"knowledge-memory",
23-
"location-services",
24-
"monitoring",
25-
"search",
26-
"version-control",
27-
"integrations",
28-
"other-tools",
29-
"developer-tools"
30-
];
17+
// Fetch categories from API
18+
useEffect(() => {
19+
const fetchCategories = async () => {
20+
try {
21+
setIsLoading(true);
22+
const response = await fetch('/v1/hub/server_categories');
23+
if (!response.ok) {
24+
throw new Error('Failed to fetch categories');
25+
}
26+
const data = await response.json();
27+
setCategoryKeys(data);
28+
} catch (error) {
29+
console.error('Error fetching categories:', error);
30+
// Show an empty menu if the API call fails
31+
setCategoryKeys([]);
32+
} finally {
33+
setIsLoading(false);
34+
}
35+
};
36+
37+
fetchCategories();
38+
}, []);
3139

3240
// Map category keys to their respective SVG icons
3341
const categoryIcons: Record<string, JSX.Element> = {
@@ -149,17 +157,21 @@ export function CategoriesDropdown({ isMobile, onSelectMobile }: CategoryProps)
149157
{t('nav.categories')}
150158
</div>
151159
<div className="flex flex-col space-y-2 mt-1 pl-4">
152-
{categoryKeys.map((key, index) => (
153-
<Link
154-
key={index}
155-
to={`/category/${key}`}
156-
className="text-gray-600 hover:text-indigo-600 text-sm flex items-center"
157-
onClick={handleCategoryClick}
158-
>
159-
{categoryIcons[key]}
160-
{t(`category.${key}`)}
161-
</Link>
162-
))}
160+
{isLoading ? (
161+
<div className="text-gray-500 text-sm pl-2">Loading categories...</div>
162+
) : (
163+
categoryKeys.map((key, index) => (
164+
<Link
165+
key={index}
166+
to={`/category/${key}`}
167+
className="text-gray-600 hover:text-indigo-600 text-sm flex items-center"
168+
onClick={handleCategoryClick}
169+
>
170+
{categoryIcons[key]}
171+
{t(`category.${key}`)}
172+
</Link>
173+
))
174+
)}
163175
</div>
164176
</div>
165177
);
@@ -210,19 +222,23 @@ export function CategoriesDropdown({ isMobile, onSelectMobile }: CategoryProps)
210222
ref={categoriesMenuRef}
211223
>
212224
<div className="grid grid-cols-1 gap-1">
213-
{categoryKeys.map((key, index) => (
214-
<Link
215-
key={index}
216-
to={`/category/${key}`}
217-
className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-indigo-600"
218-
onClick={handleCategoryClick}
219-
>
220-
<div className="flex items-center">
221-
{categoryIcons[key]}
222-
{t(`category.${key}`)}
223-
</div>
224-
</Link>
225-
))}
225+
{isLoading ? (
226+
<div className="px-4 py-2 text-sm text-gray-500">Loading categories...</div>
227+
) : (
228+
categoryKeys.map((key, index) => (
229+
<Link
230+
key={index}
231+
to={`/category/${key}`}
232+
className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-indigo-600"
233+
onClick={handleCategoryClick}
234+
>
235+
<div className="flex items-center">
236+
{categoryIcons[key]}
237+
{t(`category.${key}`)}
238+
</div>
239+
</Link>
240+
))
241+
)}
226242
</div>
227243
</div>
228244
)}

server/src/lib/mcpCategories.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// MCP server categories
22
export const MCP_SERVER_CATEGORIES = [
3-
"Browser Automation",
4-
"Cloud Platforms",
5-
"Communication",
6-
"Databases",
7-
"File Systems",
8-
"Knowledge & Memory",
9-
"Location Services",
10-
"Monitoring",
11-
"Search",
12-
"Version Control",
13-
"Integrations",
14-
"Other Tools",
15-
"Developer Tools"
3+
"browser-automation",
4+
"cloud-platforms",
5+
"communication",
6+
"databases",
7+
"file-systems",
8+
"knowledge-memory",
9+
"location-services",
10+
"monitoring",
11+
"search",
12+
"version-control",
13+
"integrations",
14+
"other-tools",
15+
"developer-tools"
1616
];

0 commit comments

Comments
 (0)