Fix search box (fix #47)
This commit is contained in:
@@ -78,6 +78,7 @@ export default function Search() {
|
|||||||
const defaultStyles = useDefaultStyles();
|
const defaultStyles = useDefaultStyles();
|
||||||
|
|
||||||
// Prepare state
|
// Prepare state
|
||||||
|
const [fuseIsReady, setFuseReady] = useState(false);
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const albums = useTypedSelector(state => state.music.albums.entities);
|
const albums = useTypedSelector(state => state.music.albums.entities);
|
||||||
const [fuseResults, setFuseResults] = useState<CombinedResults>([]);
|
const [fuseResults, setFuseResults] = useState<CombinedResults>([]);
|
||||||
@@ -100,7 +101,8 @@ export default function Search() {
|
|||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fuse.current = new Fuse(Object.values(albums) as Album[], fuseOptions);
|
fuse.current = new Fuse(Object.values(albums) as Album[], fuseOptions);
|
||||||
}, [albums]);
|
setFuseReady(true);
|
||||||
|
}, [albums, setFuseReady]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function retrieves search results from Jellyfin. It is a seperate
|
* This function retrieves search results from Jellyfin. It is a seperate
|
||||||
@@ -205,7 +207,7 @@ export default function Search() {
|
|||||||
|
|
||||||
// GUARD: We cannot search for stuff unless Fuse is loaded with results.
|
// GUARD: We cannot search for stuff unless Fuse is loaded with results.
|
||||||
// Therefore we delay rendering to when we are certain it's there.
|
// Therefore we delay rendering to when we are certain it's there.
|
||||||
if (!fuse.current) {
|
if (!fuseIsReady) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user