diff --git a/src/showplanner/libraries.tsx b/src/showplanner/libraries.tsx index 930755f..82938db 100644 --- a/src/showplanner/libraries.tsx +++ b/src/showplanner/libraries.tsx @@ -173,38 +173,42 @@ export function LibraryColumn() { } export function CentralMusicLibrary() { - const [track, setTrack] = useState(""); - const [artist, setArtist] = useState(""); - const debouncedTrack = useDebounce(track, 1000); - const debouncedArtist = useDebounce(artist, 1000); - const [items, setItems] = useState([]); + const [trackSearchTerm, setTrackSearchTerm] = useState(""); + const [artistSearchTerm, setArtistSearchTerm] = useState(""); + const debouncedTrackSearchTerm = useDebounce(trackSearchTerm, 1000); + const debouncedArtistSearchTerm = useDebounce(artistSearchTerm, 1000); + const [tracks, setTracks] = useState([]); - const [state, setState] = useState("not-searching"); + const [searchingState, setSearchingState] = useState( + "not-searching" + ); useEffect(() => { - if (debouncedTrack === "" && debouncedArtist === "") { - setItems([]); - setState("not-searching"); + if (debouncedTrackSearchTerm === "" && debouncedArtistSearchTerm === "") { + setTracks([]); + setSearchingState("not-searching"); return; } - setItems([]); - setState("searching"); - searchForTracks(artist, track).then((tracks) => { - tracks.forEach((track) => { - const id = itemId(track); - if (!(id in CML_CACHE)) { - CML_CACHE[id] = track; + setTracks([]); + setSearchingState("searching"); + searchForTracks(debouncedArtistSearchTerm, debouncedTrackSearchTerm).then( + (tracks) => { + tracks.forEach((track) => { + const id = itemId(track); + if (!(id in CML_CACHE)) { + CML_CACHE[id] = track; + } + }); + setTracks(tracks); + if (tracks.length === 0) { + setSearchingState("no-results"); + } else { + setSearchingState("results"); + ReactTooltip.rebuild(); // Update tooltips so they appear. } - }); - setItems(tracks); - if (tracks.length === 0) { - setState("no-results"); - } else { - setState("results"); - ReactTooltip.rebuild(); // Update tooltips so they appear. } - }); - }, [debouncedTrack, debouncedArtist, artist, track]); + ); + }, [debouncedTrackSearchTerm, debouncedArtistSearchTerm]); return (
@@ -212,19 +216,19 @@ export function CentralMusicLibrary() { className="form-control form-control-sm" type="text" placeholder="Filter by track..." - value={track} - onChange={(e) => setTrack(e.target.value)} + value={trackSearchTerm} + onChange={(e) => setTrackSearchTerm(e.target.value)} /> setArtist(e.target.value)} + value={artistSearchTerm} + onChange={(e) => setArtistSearchTerm(e.target.value)} />
- + {(provided, snapshot) => (
- {items.map((item, index) => ( + {tracks.map((item, index) => ( ([]); - const [state, setState] = useState("not-searching"); + const [searchingState, setSearchingState] = useState( + "not-searching" + ); useEffect(() => { async function load() { setItems([]); - setState("searching"); + setSearchingState("searching"); const libItems = await loadPlaylistLibrary(libraryId); libItems.forEach((item) => { const id = itemId(item); @@ -270,9 +276,9 @@ export function ManagedPlaylistLibrary({ libraryId }: { libraryId: string }) { }); setItems(libItems); if (libItems.length === 0) { - setState("no-results"); + setSearchingState("no-results"); } else { - setState("results"); + setSearchingState("results"); ReactTooltip.rebuild(); // Update tooltips so they appear. } } @@ -285,19 +291,19 @@ export function ManagedPlaylistLibrary({ libraryId }: { libraryId: string }) { className="form-control form-control-sm" type="text" placeholder="Filter by track..." - value={track} - onChange={(e) => setTrack(e.target.value)} + value={trackSearchTerm} + onChange={(e) => setTrackSearchTerm(e.target.value)} /> setArtist(e.target.value)} + value={artistSearchTerm} + onChange={(e) => setArtistSearchTerm(e.target.value)} />
- + {(provided, snapshot) => (
-1 + .indexOf(debouncedTrackSearchTerm.toLowerCase()) > -1 ) .filter( (its) => its.artist .toString() .toLowerCase() - .indexOf(debouncedArtist.toLowerCase()) > -1 + .indexOf(debouncedArtistSearchTerm.toLowerCase()) > -1 ) .map((item, index) => ( ([]); - const [state, setState] = useState("not-searching"); + const [searchingState, setSearchingState] = useState( + "not-searching" + ); useEffect(() => { async function load() { setItems([]); - setState("searching"); + setSearchingState("searching"); const libItems = await loadAuxLibrary(libraryId); libItems.forEach((item) => { const id = itemId(item); @@ -359,9 +367,9 @@ export function AuxLibrary({ libraryId }: { libraryId: string }) { setItems(libItems); ReactTooltip.rebuild(); // Update tooltips so they appear. if (libItems.length === 0) { - setState("no-results"); + setSearchingState("no-results"); } else { - setState("results"); + setSearchingState("results"); } } load(); @@ -378,7 +386,7 @@ export function AuxLibrary({ libraryId }: { libraryId: string }) { />
- + {(provided, snapshot) => (
- {state === "not-searching" && } - {state === "searching" && } - {state === "no-results" && } + {searchingState === "not-searching" && } + {searchingState === "searching" && ( + + )} + {searchingState === "no-results" && }
- {state === "not-searching" + {searchingState === "not-searching" ? "Enter a search term." - : state === "searching" + : searchingState === "searching" ? "Searching..." - : state === "no-results" + : searchingState === "no-results" ? "No results." : ""}