Set title and convert all class component to functional #4

Merged
torjus merged 6 commits from feature/set-title into master 2023-12-05 02:22:23 +00:00
Showing only changes of commit c193e5da2d - Show all commits

View File

@ -3,43 +3,37 @@ import React from "react";
type StreamSelectCallback = (selected: string) => void
type MenuProps = {
interface MenuProps {
items: string[]
selectedItem: string | undefined
selectedItem: string | null
selectCallback: StreamSelectCallback
}
export class Menu extends React.Component<MenuProps> {
constructor(props: MenuProps) {
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() {
export function Menu({ items, selectedItem, selectCallback }: MenuProps) {
const menuitems = () => {
return (
<>
{this.props.items.map((value, idx) => {
if (this.props.selectedItem == value) {
{items.map((value, idx) => {
if (selectedItem == value) {
return <li key={idx} className="menu-item menu-selected"><a href={"#" + value} className="menu-link">{value}</a></li>
} else {
return <li key={idx} onClick={() => {
this.props.selectCallback(value)
selectCallback(value)
}} 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>
)
}