feat: refactoring modules
This commit is contained in:
30
furumi-node-player/client/src/components/Breadcrumbs.tsx
Normal file
30
furumi-node-player/client/src/components/Breadcrumbs.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
type Crumb = {
|
||||
label: string
|
||||
action?: () => void
|
||||
}
|
||||
|
||||
type BreadcrumbsProps = {
|
||||
items: Crumb[]
|
||||
}
|
||||
|
||||
export function Breadcrumbs({ items }: BreadcrumbsProps) {
|
||||
if (!items.length) return null
|
||||
|
||||
return (
|
||||
<div className="breadcrumb">
|
||||
{items.map((item, index) => {
|
||||
const isLast = index === items.length - 1
|
||||
return (
|
||||
<span key={`${item.label}-${index}`}>
|
||||
{!isLast && item.action ? (
|
||||
<span onClick={item.action}>{item.label}</span>
|
||||
) : (
|
||||
<span>{item.label}</span>
|
||||
)}
|
||||
{!isLast ? ' / ' : ''}
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
54
furumi-node-player/client/src/components/LibraryList.tsx
Normal file
54
furumi-node-player/client/src/components/LibraryList.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import type { MouseEvent } from 'react'
|
||||
|
||||
type LibraryListButton = {
|
||||
title: string
|
||||
onClick: (ev: MouseEvent<HTMLButtonElement>) => void
|
||||
}
|
||||
|
||||
type LibraryListItem = {
|
||||
key: string
|
||||
className: string
|
||||
icon: string
|
||||
name: string
|
||||
detail?: string
|
||||
nameClassName?: string
|
||||
onClick: () => void
|
||||
button?: LibraryListButton
|
||||
}
|
||||
|
||||
type LibraryListProps = {
|
||||
loading: boolean
|
||||
error: string | null
|
||||
items: LibraryListItem[]
|
||||
}
|
||||
|
||||
export function LibraryList({ loading, error, items }: LibraryListProps) {
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ padding: '2rem', textAlign: 'center' }}>
|
||||
<div className="spinner" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div style={{ padding: '1rem', color: 'var(--danger)' }}>{error}</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{items.map((item) => (
|
||||
<div key={item.key} className={item.className} onClick={item.onClick}>
|
||||
<span className="icon">{item.icon}</span>
|
||||
<span className={item.nameClassName ?? 'name'}>{item.name}</span>
|
||||
{item.detail ? <span className="detail">{item.detail}</span> : null}
|
||||
{item.button ? (
|
||||
<button className="add-btn" title={item.button.title} onClick={item.button.onClick}>
|
||||
➕
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
}
|
||||
30
furumi-node-player/client/src/components/SearchDropdown.tsx
Normal file
30
furumi-node-player/client/src/components/SearchDropdown.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
type SearchResultItem = {
|
||||
result_type: string
|
||||
slug: string
|
||||
name: string
|
||||
detail?: string
|
||||
}
|
||||
|
||||
type SearchDropdownProps = {
|
||||
isOpen: boolean
|
||||
results: SearchResultItem[]
|
||||
onSelect: (type: string, slug: string) => void
|
||||
}
|
||||
|
||||
export function SearchDropdown({ isOpen, results, onSelect }: SearchDropdownProps) {
|
||||
return (
|
||||
<div className={`search-dropdown${isOpen ? ' open' : ''}`}>
|
||||
{results.map((r) => (
|
||||
<div
|
||||
key={`${r.result_type}:${r.slug}`}
|
||||
className="search-result"
|
||||
onClick={() => onSelect(r.result_type, r.slug)}
|
||||
>
|
||||
<span className="sr-type">{r.result_type}</span>
|
||||
{r.name}
|
||||
{r.detail ? <span className="sr-detail">{r.detail}</span> : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user