Files
QueueCube/frontend/src/components/SongTable.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

import React, { useEffect, useRef, ReactNode } from "react";
2025-02-15 16:28:47 -08:00
import SongRow, { PlayState } from "./SongRow";
import { PlaylistItem } from "../api/player";
2025-02-15 14:56:58 -08:00
2025-02-15 15:22:07 -08:00
interface SongTableProps {
2025-02-15 16:28:47 -08:00
songs: PlaylistItem[];
isPlaying: boolean
auxControlProvider?: (song: PlaylistItem) => ReactNode;
2025-02-15 15:22:07 -08:00
onDelete: (index: number) => void;
onSkipTo: (index: number) => void;
}
2025-02-15 14:56:58 -08:00
const SongTable: React.FC<SongTableProps> = ({ songs, isPlaying, auxControlProvider, onDelete, onSkipTo }) => {
2025-02-15 16:28:47 -08:00
const nowPlayingIndex = songs.findIndex(song => song.playing ?? false);
const songTableRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const songTable = songTableRef.current;
if (songTable) {
songTable.scrollTop = nowPlayingIndex * 100;
}
}, [nowPlayingIndex]);
2025-02-15 14:56:58 -08:00
return (
2025-02-23 17:03:29 -08:00
<div className="flex flex-col w-full h-full overflow-y-auto" ref={songTableRef}>
2025-02-15 14:56:58 -08:00
{songs.map((song, index) => (
2025-02-15 15:22:07 -08:00
<SongRow
key={index}
song={song}
auxControl={auxControlProvider ? auxControlProvider(song) : undefined}
2025-02-15 16:28:47 -08:00
playState={
(song.playing ?? false) ? (isPlaying ? PlayState.Playing : PlayState.Paused)
: PlayState.NotPlaying
}
2025-02-15 15:22:07 -08:00
onDelete={() => onDelete(index)}
onPlay={() => onSkipTo(index)}
/>
2025-02-15 14:56:58 -08:00
))}
</div>
);
};
export default SongTable;