2025-02-15 16:28:47 -08:00
|
|
|
|
import classNames from 'classnames';
|
2025-02-23 17:58:26 -08:00
|
|
|
|
import React, { useState, useRef, useEffect, ReactNode } from 'react';
|
2025-11-15 17:58:29 -08:00
|
|
|
|
import { FaPlay, FaVolumeUp, FaVolumeOff, FaExclamationTriangle } from 'react-icons/fa';
|
2025-02-15 22:15:59 -08:00
|
|
|
|
import { getDisplayTitle, PlaylistItem } from '../api/player';
|
2025-02-15 15:22:07 -08:00
|
|
|
|
|
2025-02-15 16:28:47 -08:00
|
|
|
|
export enum PlayState {
|
|
|
|
|
|
NotPlaying,
|
|
|
|
|
|
Playing,
|
|
|
|
|
|
Paused,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface SongRowProps {
|
|
|
|
|
|
song: PlaylistItem;
|
2025-02-23 17:58:26 -08:00
|
|
|
|
auxControl?: ReactNode;
|
2025-02-15 16:28:47 -08:00
|
|
|
|
playState: PlayState;
|
2025-02-15 15:22:07 -08:00
|
|
|
|
onDelete: () => void;
|
|
|
|
|
|
onPlay: () => void;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-23 17:58:26 -08:00
|
|
|
|
const SongRow: React.FC<SongRowProps> = ({ song, auxControl, playState, onDelete, onPlay }) => {
|
2025-02-15 15:22:07 -08:00
|
|
|
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
2025-11-15 17:58:29 -08:00
|
|
|
|
const [showErrorDetails, setShowErrorDetails] = useState(false);
|
2025-02-15 15:22:07 -08:00
|
|
|
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
|
|
|
|
if (buttonRef.current && !buttonRef.current.contains(event.target as Node)) {
|
|
|
|
|
|
setShowDeleteConfirm(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (showDeleteConfirm) {
|
|
|
|
|
|
document.addEventListener('click', handleClickOutside);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
document.removeEventListener('click', handleClickOutside);
|
|
|
|
|
|
};
|
|
|
|
|
|
}, [showDeleteConfirm]);
|
|
|
|
|
|
|
2025-02-15 22:15:59 -08:00
|
|
|
|
const displayTitle = getDisplayTitle(song);
|
2025-11-15 17:58:29 -08:00
|
|
|
|
const hasError = !!song.playbackError;
|
2025-02-15 21:40:30 -08:00
|
|
|
|
|
2025-02-15 15:22:07 -08:00
|
|
|
|
return (
|
2025-02-23 17:03:29 -08:00
|
|
|
|
<div className={classNames(
|
|
|
|
|
|
"flex flex-row w-full h-20 px-2 py-2 items-center border-b gap-2 transition-colors shrink-0", {
|
2025-02-23 12:51:21 -08:00
|
|
|
|
"qc-highlighted": (playState === PlayState.Playing || playState === PlayState.Paused),
|
2025-02-15 16:28:47 -08:00
|
|
|
|
"bg-black/30": playState === PlayState.NotPlaying,
|
|
|
|
|
|
})}>
|
2025-02-15 15:22:07 -08:00
|
|
|
|
<div className="flex flex-row gap-2">
|
2025-11-15 17:58:29 -08:00
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<button
|
|
|
|
|
|
className={classNames(
|
|
|
|
|
|
"transition-colors px-3 py-1 rounded",
|
|
|
|
|
|
hasError ? "text-amber-300 hover:text-amber-100" : "text-white/40 hover:text-white"
|
|
|
|
|
|
)}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
if (hasError) {
|
|
|
|
|
|
setShowErrorDetails((prev) => !prev);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
onPlay();
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
onMouseEnter={() => {
|
|
|
|
|
|
if (hasError) {
|
|
|
|
|
|
setShowErrorDetails(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
onMouseLeave={() => {
|
|
|
|
|
|
if (hasError) {
|
|
|
|
|
|
setShowErrorDetails(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
title={hasError ? song.playbackError : undefined}
|
|
|
|
|
|
>
|
|
|
|
|
|
{
|
|
|
|
|
|
hasError ? <FaExclamationTriangle size={12} /> :
|
|
|
|
|
|
playState === PlayState.Playing ? <FaVolumeUp size={12} />
|
|
|
|
|
|
: playState === PlayState.Paused ? <FaVolumeOff size={12} />
|
|
|
|
|
|
: <FaPlay size={12} />
|
|
|
|
|
|
}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
{hasError && showErrorDetails && (
|
|
|
|
|
|
<div className="absolute z-10 top-full left-0 mt-1 w-64 p-2 text-xs text-white bg-red-600/90 rounded shadow-lg">
|
|
|
|
|
|
<div className="font-semibold mb-1">Playback error</div>
|
|
|
|
|
|
<div className="break-words">{song.playbackError}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2025-02-15 15:22:07 -08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex-grow min-w-0">
|
2025-02-15 16:28:47 -08:00
|
|
|
|
{
|
2025-02-15 21:40:30 -08:00
|
|
|
|
displayTitle ? (
|
2025-02-15 16:28:47 -08:00
|
|
|
|
<div>
|
|
|
|
|
|
<div className="text-white text-md truncate text-bold">
|
2025-02-15 21:40:30 -08:00
|
|
|
|
{displayTitle}
|
2025-02-15 16:28:47 -08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-white/80 text-xs truncate">
|
|
|
|
|
|
{song.filename}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="text-white text-md truncate text-bold">
|
|
|
|
|
|
{song.filename}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2025-02-15 15:22:07 -08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-row gap-2">
|
2025-02-23 17:58:26 -08:00
|
|
|
|
{auxControl}
|
|
|
|
|
|
|
2025-02-15 15:22:07 -08:00
|
|
|
|
<button
|
|
|
|
|
|
ref={buttonRef}
|
2025-02-23 12:51:21 -08:00
|
|
|
|
className="text-red-100 px-3 py-1 bg-red-500/40 rounded"
|
2025-02-15 15:22:07 -08:00
|
|
|
|
onClick={(e) => {
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
if (showDeleteConfirm) {
|
|
|
|
|
|
setShowDeleteConfirm(false);
|
|
|
|
|
|
onDelete();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setShowDeleteConfirm(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{showDeleteConfirm ? 'Delete' : '×'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default SongRow;
|