Replace menu with functional component

This commit is contained in:
Torjus Håkestad 2023-12-05 02:21:38 +01:00
parent a267f9e0df
commit c193e5da2d

View File

@ -3,43 +3,37 @@ import React from "react";
type StreamSelectCallback = (selected: string) => void type StreamSelectCallback = (selected: string) => void
type MenuProps = { interface MenuProps {
items: string[] items: string[]
selectedItem: string | undefined selectedItem: string | null
selectCallback: StreamSelectCallback selectCallback: StreamSelectCallback
} }
export class Menu extends React.Component<MenuProps> { export function Menu({ items, selectedItem, selectCallback }: MenuProps) {
constructor(props: MenuProps) { const menuitems = () => {
super(props)
}
render() {
return (
<div id="menu">
<aside>
<a className="menu-heading" href="#">stream.t-juice.club</a>
<ul className="menu-list">
{this.menuitems()}
</ul>
</aside>
</div>
)
}
private menuitems() {
return ( return (
<> <>
{this.props.items.map((value, idx) => { {items.map((value, idx) => {
if (this.props.selectedItem == value) { if (selectedItem == value) {
return <li key={idx} className="menu-item menu-selected"><a href={"#" + value} className="menu-link">{value}</a></li> return <li key={idx} className="menu-item menu-selected"><a href={"#" + value} className="menu-link">{value}</a></li>
} else { } else {
return <li key={idx} onClick={() => { return <li key={idx} onClick={() => {
this.props.selectCallback(value) selectCallback(value)
}} className="menu-item"><a href={"#" + value} className="menu-link">{value}</a></li> }} className="menu-item"><a href={"#" + value} className="menu-link">{value}</a></li>
} }
})} })}
</> </>
) )
} }
return (
<div id="menu">
<aside>
<a className="menu-heading" href="#">stream.t-juice.club</a>
<ul className="menu-list">
{menuitems()}
</ul>
</aside>
</div>
)
} }