mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Initial Commit: Implemented library list
This commit is contained in:
1 parent
704d128289
commit
fceaab6d78
36 files changed
+3910
No files matched your search
@@ -0,0 +1,20 @@
|
||||
interface Props {
|
||||
value: number
|
||||
}
|
||||
|
||||
// Compact 5-star rating. Filled stars use the gold accent; empties are faint.
|
||||
export function RatingStars({ value }: Props) {
|
||||
if (!value) return <span className="text-faint">—</span>
|
||||
return (
|
||||
<span className="whitespace-nowrap tracking-tight" title={`${value} / 5`}>
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<span
|
||||
key={i}
|
||||
className={i <= value ? 'text-gold' : 'text-ink-600'}
|
||||
>
|
||||
★
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { api, type PlaylistNode } from '../api'
|
||||
|
||||
export type Source = { kind: 'all' } | { kind: 'playlist'; id: string; name: string }
|
||||
|
||||
interface Props {
|
||||
source: Source
|
||||
onSelect: (s: Source) => void
|
||||
}
|
||||
|
||||
const icons: Record<string, string> = {
|
||||
FOLDER: '▸',
|
||||
PLAYLIST: '♫',
|
||||
SMARTLIST: '✦',
|
||||
}
|
||||
|
||||
function NodeRow({
|
||||
node,
|
||||
depth,
|
||||
source,
|
||||
onSelect,
|
||||
}: {
|
||||
node: PlaylistNode
|
||||
depth: number
|
||||
source: Source
|
||||
onSelect: (s: Source) => void
|
||||
}) {
|
||||
const [open, setOpen] = useState(true)
|
||||
const isFolder = node.type === 'FOLDER'
|
||||
const selected = source.kind === 'playlist' && source.id === node.id
|
||||
const selectable = node.type === 'PLAYLIST'
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (isFolder) setOpen((o) => !o)
|
||||
else if (selectable) onSelect({ kind: 'playlist', id: node.id, name: node.name })
|
||||
}}
|
||||
className={`group flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors ${
|
||||
selected
|
||||
? 'bg-accent-soft text-text'
|
||||
: 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
} ${!selectable && !isFolder ? 'cursor-default opacity-70' : ''}`}
|
||||
style={{ paddingLeft: `${8 + depth * 14}px` }}
|
||||
>
|
||||
<span
|
||||
className={`w-3 shrink-0 text-center text-[11px] ${
|
||||
isFolder ? 'text-faint' : node.type === 'SMARTLIST' ? 'text-pink' : 'text-accent'
|
||||
} ${isFolder && open ? 'rotate-90' : ''} transition-transform`}
|
||||
>
|
||||
{icons[node.type]}
|
||||
</span>
|
||||
<span className="flex-1 truncate">{node.name}</span>
|
||||
{node.type === 'PLAYLIST' && (
|
||||
<span className="shrink-0 rounded bg-ink-800 px-1.5 py-0.5 text-[10px] tabular-nums text-faint group-hover:bg-ink-700">
|
||||
{node.count}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
{isFolder && open && node.children.length > 0 && (
|
||||
<div>
|
||||
{node.children.map((c) => (
|
||||
<NodeRow
|
||||
key={c.id}
|
||||
node={c}
|
||||
depth={depth + 1}
|
||||
source={source}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function Sidebar({ source, onSelect }: Props) {
|
||||
const { data: playlists, isLoading } = useQuery({
|
||||
queryKey: ['playlists'],
|
||||
queryFn: api.playlists,
|
||||
})
|
||||
|
||||
return (
|
||||
<aside className="flex h-full w-64 shrink-0 flex-col border-r border-line bg-ink-900">
|
||||
<div className="flex items-center gap-2 px-4 py-4">
|
||||
<div className="flex h-7 w-7 items-center justify-center rounded-md bg-accent text-sm font-bold text-ink-950">
|
||||
K
|
||||
</div>
|
||||
<div className="text-[15px] font-semibold tracking-tight">konduktor</div>
|
||||
</div>
|
||||
|
||||
<div className="px-2">
|
||||
<button
|
||||
onClick={() => onSelect({ kind: 'all' })}
|
||||
className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors ${
|
||||
source.kind === 'all'
|
||||
? 'bg-accent-soft text-text'
|
||||
: 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
}`}
|
||||
>
|
||||
<span className="w-3 text-center text-[11px] text-mint">◈</span>
|
||||
<span className="flex-1">All Tracks</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 px-4 text-[10px] font-semibold uppercase tracking-wider text-faint">
|
||||
Playlists
|
||||
</div>
|
||||
<div className="mt-1 flex-1 overflow-y-auto px-2 pb-4">
|
||||
{isLoading && <div className="px-2 py-2 text-sm text-faint">Loading…</div>}
|
||||
{playlists?.map((n) => (
|
||||
<NodeRow
|
||||
key={n.id}
|
||||
node={n}
|
||||
depth={0}
|
||||
source={source}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
interface Props {
|
||||
showing: number
|
||||
total: number
|
||||
sourceName: string
|
||||
loading?: boolean
|
||||
}
|
||||
|
||||
export function StatusBar({ showing, total, sourceName, loading }: Props) {
|
||||
return (
|
||||
<div className="flex items-center gap-3 border-t border-line bg-ink-900 px-4 py-2 text-xs text-muted">
|
||||
<span className="font-medium text-text">{sourceName}</span>
|
||||
<span className="text-faint">·</span>
|
||||
{loading ? (
|
||||
<span>Loading…</span>
|
||||
) : (
|
||||
<span className="tabular-nums">
|
||||
{showing === total ? (
|
||||
<>{total.toLocaleString()} tracks</>
|
||||
) : (
|
||||
<>
|
||||
{showing.toLocaleString()} of {total.toLocaleString()} tracks
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
<span className="ml-auto text-faint">konduktor · phase 2</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
|
||||
export interface Filters {
|
||||
search: string
|
||||
genre: string
|
||||
key: string
|
||||
bpmMin: string
|
||||
bpmMax: string
|
||||
ratingMin: number
|
||||
hasCues: 'any' | 'yes' | 'no'
|
||||
}
|
||||
|
||||
export const emptyFilters: Filters = {
|
||||
search: '',
|
||||
genre: '',
|
||||
key: '',
|
||||
bpmMin: '',
|
||||
bpmMax: '',
|
||||
ratingMin: 0,
|
||||
hasCues: 'any',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
filters: Filters
|
||||
onChange: (f: Filters) => void
|
||||
}
|
||||
|
||||
const selectCls =
|
||||
'rounded-md border border-line bg-ink-850 px-2.5 py-1.5 text-sm text-text outline-none focus:border-accent hover:border-ink-600 transition-colors'
|
||||
|
||||
export function Toolbar({ filters, onChange }: Props) {
|
||||
const { data: facets } = useQuery({ queryKey: ['facets'], queryFn: api.facets })
|
||||
const set = (patch: Partial<Filters>) => onChange({ ...filters, ...patch })
|
||||
const active =
|
||||
filters.search ||
|
||||
filters.genre ||
|
||||
filters.key ||
|
||||
filters.bpmMin ||
|
||||
filters.bpmMax ||
|
||||
filters.ratingMin > 0 ||
|
||||
filters.hasCues !== 'any'
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2 border-b border-line bg-ink-900 px-4 py-3">
|
||||
<div className="relative">
|
||||
<span className="pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-faint">
|
||||
⌕
|
||||
</span>
|
||||
<input
|
||||
value={filters.search}
|
||||
onChange={(e) => set({ search: e.target.value })}
|
||||
placeholder="Search artist, title, album…"
|
||||
className="w-64 rounded-md border border-line bg-ink-850 py-1.5 pl-8 pr-3 text-sm text-text outline-none placeholder:text-faint focus:border-accent"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<select
|
||||
value={filters.genre}
|
||||
onChange={(e) => set({ genre: e.target.value })}
|
||||
className={selectCls}
|
||||
>
|
||||
<option value="">All genres</option>
|
||||
{facets?.genres.map((g) => (
|
||||
<option key={g.name} value={g.name}>
|
||||
{g.name.trim() || '(blank)'} · {g.count}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<select
|
||||
value={filters.key}
|
||||
onChange={(e) => set({ key: e.target.value })}
|
||||
className={selectCls}
|
||||
>
|
||||
<option value="">All keys</option>
|
||||
{facets?.keys.map((k) => (
|
||||
<option key={k.name} value={k.name}>
|
||||
{k.name} · {k.count}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<input
|
||||
value={filters.bpmMin}
|
||||
onChange={(e) => set({ bpmMin: e.target.value.replace(/[^\d.]/g, '') })}
|
||||
placeholder="min"
|
||||
className="w-14 rounded-md border border-line bg-ink-850 px-2 py-1.5 text-center text-sm tabular-nums outline-none focus:border-accent placeholder:text-faint"
|
||||
/>
|
||||
<span className="text-xs text-faint">BPM</span>
|
||||
<input
|
||||
value={filters.bpmMax}
|
||||
onChange={(e) => set({ bpmMax: e.target.value.replace(/[^\d.]/g, '') })}
|
||||
placeholder="max"
|
||||
className="w-14 rounded-md border border-line bg-ink-850 px-2 py-1.5 text-center text-sm tabular-nums outline-none focus:border-accent placeholder:text-faint"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<select
|
||||
value={filters.ratingMin}
|
||||
onChange={(e) => set({ ratingMin: Number(e.target.value) })}
|
||||
className={selectCls}
|
||||
>
|
||||
<option value={0}>Any rating</option>
|
||||
{[1, 2, 3, 4, 5].map((r) => (
|
||||
<option key={r} value={r}>
|
||||
{'★'.repeat(r)}+
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<select
|
||||
value={filters.hasCues}
|
||||
onChange={(e) => set({ hasCues: e.target.value as Filters['hasCues'] })}
|
||||
className={selectCls}
|
||||
>
|
||||
<option value="any">Any cues</option>
|
||||
<option value="yes">Has cues</option>
|
||||
<option value="no">No cues</option>
|
||||
</select>
|
||||
|
||||
{active && (
|
||||
<button
|
||||
onClick={() => onChange(emptyFilters)}
|
||||
className="ml-auto rounded-md px-2.5 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
>
|
||||
Clear filters
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import { useMemo, useRef } from 'react'
|
||||
import {
|
||||
createColumnHelper,
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
getSortedRowModel,
|
||||
useReactTable,
|
||||
type SortingState,
|
||||
} from '@tanstack/react-table'
|
||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||
import type { Track } from '../api'
|
||||
import { formatBpm, formatDuration, keyColor } from '../lib/format'
|
||||
import { RatingStars } from './RatingStars'
|
||||
|
||||
const col = createColumnHelper<Track>()
|
||||
|
||||
const columns = [
|
||||
col.accessor('title', {
|
||||
header: 'Title',
|
||||
size: 320,
|
||||
cell: (c) => (
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-medium text-text">
|
||||
{c.getValue() || <span className="text-faint">Untitled</span>}
|
||||
</div>
|
||||
<div className="truncate text-xs text-muted">{c.row.original.artist}</div>
|
||||
</div>
|
||||
),
|
||||
}),
|
||||
col.accessor('album', {
|
||||
header: 'Album',
|
||||
size: 200,
|
||||
cell: (c) => <span className="truncate text-muted">{c.getValue() || '—'}</span>,
|
||||
}),
|
||||
col.accessor('genre', {
|
||||
header: 'Genre',
|
||||
size: 150,
|
||||
cell: (c) => {
|
||||
const g = c.getValue()?.trim()
|
||||
return g ? (
|
||||
<span className="truncate text-muted">{g}</span>
|
||||
) : (
|
||||
<span className="text-faint">—</span>
|
||||
)
|
||||
},
|
||||
}),
|
||||
col.accessor('bpm', {
|
||||
header: 'BPM',
|
||||
size: 74,
|
||||
cell: (c) => <span className="tabular-nums text-text">{formatBpm(c.getValue())}</span>,
|
||||
}),
|
||||
col.accessor('key', {
|
||||
header: 'Key',
|
||||
size: 64,
|
||||
cell: (c) => {
|
||||
const k = c.getValue()
|
||||
if (!k) return <span className="text-faint">—</span>
|
||||
return (
|
||||
<span
|
||||
className="rounded px-1.5 py-0.5 text-xs font-semibold"
|
||||
style={{ color: keyColor(k), background: 'color-mix(in srgb, currentColor 14%, transparent)' }}
|
||||
>
|
||||
{k}
|
||||
</span>
|
||||
)
|
||||
},
|
||||
}),
|
||||
col.accessor('rating', {
|
||||
header: 'Rating',
|
||||
size: 92,
|
||||
cell: (c) => <RatingStars value={c.getValue()} />,
|
||||
}),
|
||||
col.accessor('length', {
|
||||
header: 'Time',
|
||||
size: 64,
|
||||
cell: (c) => <span className="tabular-nums text-muted">{formatDuration(c.getValue())}</span>,
|
||||
}),
|
||||
col.accessor('cue_count', {
|
||||
header: 'Cues',
|
||||
size: 72,
|
||||
cell: (c) => {
|
||||
const n = c.getValue()
|
||||
const grid = c.row.original.has_grid
|
||||
return (
|
||||
<span className="flex items-center gap-1 tabular-nums">
|
||||
<span className={n > 0 ? 'text-text' : 'text-faint'}>{n}</span>
|
||||
{grid && <span className="text-[10px] text-mint" title="Beatgrid analyzed">⊞</span>}
|
||||
</span>
|
||||
)
|
||||
},
|
||||
}),
|
||||
col.accessor('playcount', {
|
||||
header: 'Plays',
|
||||
size: 68,
|
||||
cell: (c) => <span className="tabular-nums text-muted">{c.getValue() || 0}</span>,
|
||||
}),
|
||||
]
|
||||
|
||||
interface Props {
|
||||
tracks: Track[]
|
||||
sorting: SortingState
|
||||
onSortingChange: (s: SortingState) => void
|
||||
// Playlists have a meaningful order; disable default sort to preserve it.
|
||||
ordered?: boolean
|
||||
}
|
||||
|
||||
export function TrackTable({ tracks, sorting, onSortingChange }: Props) {
|
||||
const table = useReactTable({
|
||||
data: tracks,
|
||||
columns,
|
||||
state: { sorting },
|
||||
onSortingChange: (updater) =>
|
||||
onSortingChange(typeof updater === 'function' ? updater(sorting) : updater),
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
})
|
||||
|
||||
const rows = table.getRowModel().rows
|
||||
const parentRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const virtualizer = useVirtualizer({
|
||||
count: rows.length,
|
||||
getScrollElement: () => parentRef.current,
|
||||
estimateSize: () => 44,
|
||||
overscan: 12,
|
||||
})
|
||||
|
||||
const totalWidth = useMemo(
|
||||
() => table.getTotalSize(),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[],
|
||||
)
|
||||
const virtualRows = virtualizer.getVirtualItems()
|
||||
|
||||
return (
|
||||
<div ref={parentRef} className="h-full overflow-auto">
|
||||
<div style={{ width: totalWidth, minWidth: '100%' }}>
|
||||
{/* Header */}
|
||||
<div className="sticky top-0 z-10 flex border-b border-line bg-ink-850">
|
||||
<span className="w-10 shrink-0" />
|
||||
{table.getHeaderGroups()[0].headers.map((header) => {
|
||||
const sorted = header.column.getIsSorted()
|
||||
return (
|
||||
<button
|
||||
key={header.id}
|
||||
onClick={header.column.getToggleSortingHandler()}
|
||||
style={{ width: header.getSize() }}
|
||||
className="flex items-center gap-1 px-3 py-2.5 text-left text-[11px] font-semibold uppercase tracking-wider text-muted hover:text-text"
|
||||
>
|
||||
{flexRender(header.column.columnDef.header, header.getContext())}
|
||||
<span className="text-accent">
|
||||
{sorted === 'asc' ? '↑' : sorted === 'desc' ? '↓' : ''}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Virtualized rows */}
|
||||
<div style={{ height: virtualizer.getTotalSize(), position: 'relative' }}>
|
||||
{virtualRows.map((vr) => {
|
||||
const row = rows[vr.index]
|
||||
return (
|
||||
<div
|
||||
key={row.id}
|
||||
className="absolute left-0 flex items-center border-b border-ink-850 text-sm hover:bg-ink-850"
|
||||
style={{
|
||||
top: 0,
|
||||
transform: `translateY(${vr.start}px)`,
|
||||
height: vr.size,
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<span className="w-10 shrink-0 pr-2 text-right text-xs tabular-nums text-faint">
|
||||
{vr.index + 1}
|
||||
</span>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<div
|
||||
key={cell.id}
|
||||
style={{ width: cell.column.getSize() }}
|
||||
className="flex items-center overflow-hidden px-3"
|
||||
>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user