|
|
@ -1,4 +1,4 @@ |
|
|
import { ComponentType, FC } from "react"; |
|
|
|
|
|
|
|
|
import { Component, FC, useState } from "react"; |
|
|
|
|
|
|
|
|
interface ItemProps<Item> { |
|
|
interface ItemProps<Item> { |
|
|
name: string; |
|
|
name: string; |
|
|
@ -6,30 +6,22 @@ interface ItemProps<Item> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
interface ListProps<Item> { |
|
|
interface ListProps<Item> { |
|
|
|
|
|
component: Component<ItemProps<Item>>; |
|
|
map: { [key: string]: Item }; |
|
|
map: { [key: string]: Item }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: Add search box.
|
|
|
// TODO: Add search box.
|
|
|
function SearchableList<Item>( |
|
|
|
|
|
ItemComponent: ComponentType<ItemProps<Item>> |
|
|
|
|
|
): FC<ListProps<Item>> { |
|
|
|
|
|
return ({ id, map }: ListProps<Item>) => { |
|
|
|
|
|
const children = []; |
|
|
|
|
|
|
|
|
const SearchableList: FC<ListProps<Item>> = ({ component, map }) => { |
|
|
|
|
|
const children = []; |
|
|
|
|
|
for (const name in map) { |
|
|
|
|
|
children.push(<li key={name}>{component({ name, data: map[name] })}</li>); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (const name in map) { |
|
|
|
|
|
children.push( |
|
|
|
|
|
<li key={name}> |
|
|
|
|
|
<ItemComponent name={name} data={map[name]} /> |
|
|
|
|
|
</li> |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
<div className="flex flex-col h-full px-3"> |
|
|
|
|
|
<ul className="flex-grow flex flex-col">{children}</ul> |
|
|
|
|
|
</div> |
|
|
|
|
|
); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
<div className="flex flex-col h-full px-3"> |
|
|
|
|
|
<ul className="flex-grow flex flex-col">{children}</ul> |
|
|
|
|
|
</div> |
|
|
|
|
|
); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
export default SearchableList; |
|
|
export default SearchableList; |