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

59 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-02-15 15:22:07 -08:00
import React, { useState } from 'react';
2025-02-15 14:56:58 -08:00
import SongTable from './SongTable';
2025-02-15 15:22:07 -08:00
import NowPlaying from './NowPlaying';
import AddSongPanel from './AddSongPanel';
const App: React.FC = () => {
const [isPlaying, setIsPlaying] = useState(false);
const [nowPlayingSong, setNowPlayingSong] = useState<string | null>(null);
const [nowPlayingFileName, setNowPlayingFileName] = useState<string | null>(null);
const [songs, setSongs] = useState<string[]>([]);
2025-02-15 12:15:41 -08:00
2025-02-15 15:22:07 -08:00
const handleAddURL = (url: string) => {
const urlToAdd = url.trim();
if (urlToAdd) {
setSongs([...songs, urlToAdd]);
}
};
2025-02-15 12:15:41 -08:00
2025-02-15 15:22:07 -08:00
const handleDelete = (index: number) => {
setSongs(songs.filter((_, i) => i !== index));
};
2025-02-15 12:15:41 -08:00
2025-02-15 15:22:07 -08:00
const handleSkipTo = (index: number) => {
setNowPlayingSong(songs[index]);
setNowPlayingFileName(songs[index].split('/').pop() || null);
setIsPlaying(true);
};
2025-02-15 12:15:41 -08:00
return (
<div className="flex items-center justify-center h-screen w-screen bg-black py-10">
<div className="bg-violet-900 w-full md:max-w-xl h-full md:max-h-xl md:border md:rounded-2xl flex flex-col">
<NowPlaying
className="flex flex-row md:rounded-t-2xl"
2025-02-15 15:22:07 -08:00
songName={nowPlayingSong || "(Not Playing)"}
fileName={nowPlayingFileName || ""}
2025-02-15 12:15:41 -08:00
isPlaying={isPlaying}
onPlayPause={() => setIsPlaying(!isPlaying)}
onStepForward={() => {}}
onStepBackward={() => {}}
/>
2025-02-15 15:22:07 -08:00
{songs.length > 0 ? (
<SongTable
songs={songs}
onDelete={handleDelete}
onSkipTo={handleSkipTo}
/>
) : (
<div className="flex items-center justify-center h-full">
<div className="text-white text-2xl font-bold">Playlist is empty</div>
</div>
)}
<AddSongPanel onAddURL={handleAddURL} />
2025-02-15 12:15:41 -08:00
</div>
</div>
);
};
export default App;