fix(guide): sidebar types

This commit is contained in:
iCrawl 2023-04-15 23:50:18 +02:00
parent 0928c8f6ff
commit b35b935679
No known key found for this signature in database
GPG key ID: 1AB888B16355FBB2

View file

@ -6,8 +6,15 @@ import { usePathname } from 'next/navigation';
import { Section } from './Section';
import { useNav } from '~/contexts/nav';
function transformItemsByCategory(allContents: any[]) {
return allContents.reduce((accumulator: any, content) => {
const items = allContents.map((content) => ({
title: content.title,
category: content.category,
slug: content.slug,
href: content.url,
}));
function transformItemsByCategory(allContents: typeof items) {
return allContents.reduce<Record<string, typeof items>>((accumulator: any, content) => {
if (!accumulator[content.category]) {
accumulator[content.category] = [];
}
@ -17,13 +24,6 @@ function transformItemsByCategory(allContents: any[]) {
}, {});
}
const items = allContents.map((content) => ({
title: content.title,
category: content.category,
slug: content.slug,
href: content.url,
}));
const itemsByCategory = transformItemsByCategory(items);
export function Sidebar() {
@ -38,7 +38,7 @@ export function Sidebar() {
key={`${category}-${idx}`}
title={category}
>
{itemsByCategory[category].map((member, index) => (
{itemsByCategory[category]?.map((member, index) => (
<Link
className={`dark:border-dark-100 border-light-800 focus:ring-width-2 focus:ring-blurple ml-5 flex flex-col border-l p-[5px] pl-6 outline-0 focus:rounded focus:border-0 focus:ring ${
decodeURIComponent(pathname ?? '') === member.href