Type error and other fixes

This commit is contained in:
2022-04-23 20:35:53 -04:00
parent 60ed3b289d
commit 79068f24ee
8 changed files with 139 additions and 99 deletions
+27 -2
View File
@@ -8,7 +8,26 @@ type listItem = {
title: string;
};
const list: listItem[] = pl;
function toListItem(record: Record<string, any>): listItem | null {
if (!record.title)
return null;
let children: listItem[]= [];
if (record.children)
for (const child of record.children) {
const lChild = toListItem(child);
if (lChild)
children.push(lChild);
}
return {
title: record.title,
url: record.url,
children: children.length? children : undefined,
};
}
const list: listItem[] = [];
function mapChild(obj: listItem, level: number) {
if (obj.url)
@@ -38,7 +57,13 @@ function Playlists() {
<Layout name='Playlists'>
<section className='block'>
<h2>Music</h2>
{list.map(l => mapChild(l, 0))}
{
pl.map((item: Record<string, any>) => {
const lItem = toListItem(item)
if (lItem)
return mapChild(lItem, 0)
})
}
</section>
</Layout>
);