Add artist music filter

This commit is contained in:
Matthew Stratford 2020-03-22 02:26:59 +00:00
parent 768b8ccb24
commit e1430e6179

View file

@ -241,13 +241,15 @@ function Column({ id, data }: { id: number; data: PlanItem[] }) {
function CentralMusicLibrary() { function CentralMusicLibrary() {
const [track, setTrack] = useState(""); const [track, setTrack] = useState("");
const [artist, setArtist] = useState("");
const debouncedTrack = useDebounce(track, 1000); const debouncedTrack = useDebounce(track, 1000);
const debouncedArtist = useDebounce(artist, 1000);
const [items, setItems] = useState<Track[]>([]); const [items, setItems] = useState<Track[]>([]);
useEffect(() => { useEffect(() => {
if (debouncedTrack === "") { if (debouncedTrack === "" && debouncedArtist === "") {
return; return;
} }
searchForTracks("", track).then(tracks => { searchForTracks(artist, track).then(tracks => {
tracks.forEach(track => { tracks.forEach(track => {
const id = itemId(track); const id = itemId(track);
if (!(id in CML_CACHE)) { if (!(id in CML_CACHE)) {
@ -256,7 +258,7 @@ function CentralMusicLibrary() {
}); });
setItems(tracks); setItems(tracks);
}); });
}, [debouncedTrack]); }, [debouncedTrack, debouncedArtist]);
return ( return (
<> <>
<input <input
@ -265,6 +267,12 @@ function CentralMusicLibrary() {
value={track} value={track}
onChange={e => setTrack(e.target.value)} onChange={e => setTrack(e.target.value)}
/> />
<input
type="text"
placeholder="Filter by artist..."
value={artist}
onChange={e => setArtist(e.target.value)}
/>
<Droppable droppableId="$CML"> <Droppable droppableId="$CML">
{(provided, snapshot) => ( {(provided, snapshot) => (
<div ref={provided.innerRef} {...provided.droppableProps}> <div ref={provided.innerRef} {...provided.droppableProps}>