import Button from '@app/components/Button' import GradientScrollView from '@app/components/GradientScrollView' import Header from '@app/components/Header' import ListItem from '@app/components/ListItem' import NothingHere from '@app/components/NothingHere' import TextInput from '@app/components/TextInput' import { useActiveServerRefresh } from '@app/hooks/settings' import { Song, Album, Artist, SearchResults } from '@app/models/library' import { useStore, useStoreDeep } from '@app/state/store' import colors from '@app/styles/colors' import font from '@app/styles/font' import { mapById } from '@app/util/state' import { useFocusEffect, useNavigation } from '@react-navigation/native' import debounce from 'lodash.debounce' import React, { useCallback, useMemo, useRef, useState } from 'react' import { ActivityIndicator, InteractionManager, ScrollView, StatusBar, StyleSheet, TextInput as ReactTextInput, View, } from 'react-native' const SongItem = React.memo<{ item: Song }>(({ item }) => { const setQueue = useStore(store => store.setQueue) return ( setQueue([item], item.title, 'song', item.id, 0)} /> ) }) const ResultsCategory = React.memo<{ name: string query: string ids: string[] type: 'artist' | 'album' | 'song' }>(({ name, query, type, ids }) => { const items: (Album | Artist | Song)[] = useStoreDeep( useCallback( store => { switch (type) { case 'album': return mapById(store.library.albums, ids) case 'artist': return mapById(store.library.artists, ids) case 'song': return mapById(store.library.songs, ids) default: return [] } }, [ids, type], ), ) const navigation = useNavigation() if (items.length === 0) { return <> } return ( <>
{name}
{items.map(a => type === 'song' ? ( ) : ( ), )} {items.length === 5 && (