2025-02-15 16:28:47 -08:00
|
|
|
import React, { useEffect, useRef } from "react";
|
|
|
|
|
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;
|
2025-02-15 15:22:07 -08:00
|
|
|
onDelete: (index: number) => void;
|
|
|
|
|
onSkipTo: (index: number) => void;
|
|
|
|
|
}
|
2025-02-15 14:56:58 -08:00
|
|
|
|
2025-02-15 16:28:47 -08:00
|
|
|
const SongTable: React.FC<SongTableProps> = ({ songs, isPlaying, onDelete, onSkipTo }) => {
|
|
|
|
|
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-15 16:28:47 -08:00
|
|
|
<div className="flex flex-col w-full h-full overflow-y-auto border-y" 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}
|
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;
|