mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 23:02:43 +01:00
reimpl all music state into zustand
This commit is contained in:
@@ -3,18 +3,16 @@ import GradientScrollView from '@app/components/GradientScrollView'
|
||||
import Header from '@app/components/Header'
|
||||
import NothingHere from '@app/components/NothingHere'
|
||||
import PressableOpacity from '@app/components/PressableOpacity'
|
||||
import { useUpdateHomeLists } from '@app/hooks/music'
|
||||
import { useActiveServerRefresh } from '@app/hooks/server'
|
||||
import { useActiveListRefresh2 } from '@app/hooks/server'
|
||||
import { AlbumListItem } from '@app/models/music'
|
||||
import { homeListsAtom, homeListsUpdatingAtom } from '@app/state/music'
|
||||
import { selectMusic } from '@app/state/music'
|
||||
import { selectSettings } from '@app/state/settings'
|
||||
import { useStore } from '@app/state/store'
|
||||
import colors from '@app/styles/colors'
|
||||
import font from '@app/styles/font'
|
||||
import { GetAlbumListType } from '@app/subsonic/params'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
import { useAtomValue } from 'jotai/utils'
|
||||
import React from 'react'
|
||||
import React, { useCallback } from 'react'
|
||||
import { RefreshControl, ScrollView, StatusBar, StyleSheet, Text, View } from 'react-native'
|
||||
|
||||
const titles: { [key in GetAlbumListType]?: string } = {
|
||||
@@ -78,11 +76,17 @@ const Category = React.memo<{
|
||||
|
||||
const Home = () => {
|
||||
const types = useStore(selectSettings.homeLists)
|
||||
const lists = useAtomValue(homeListsAtom)
|
||||
const updating = useAtomValue(homeListsUpdatingAtom)
|
||||
const update = useUpdateHomeLists()
|
||||
const lists = useStore(selectMusic.homeLists)
|
||||
const updating = useStore(selectMusic.homeListsUpdating)
|
||||
const update = useStore(selectMusic.fetchHomeLists)
|
||||
const clear = useStore(selectMusic.clearHomeLists)
|
||||
|
||||
useActiveServerRefresh(update)
|
||||
useActiveListRefresh2(
|
||||
useCallback(() => {
|
||||
clear()
|
||||
update()
|
||||
}, [clear, update]),
|
||||
)
|
||||
|
||||
return (
|
||||
<GradientScrollView
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import CoverArt from '@app/components/CoverArt'
|
||||
import GradientFlatList from '@app/components/GradientFlatList'
|
||||
import PressableOpacity from '@app/components/PressableOpacity'
|
||||
import { useUpdateAlbumList } from '@app/hooks/music'
|
||||
import { useActiveListRefresh } from '@app/hooks/server'
|
||||
import { useActiveListRefresh2 } from '@app/hooks/server'
|
||||
import { Album } from '@app/models/music'
|
||||
import { albumListAtom, albumListUpdatingAtom } from '@app/state/music'
|
||||
import { selectMusic } from '@app/state/music'
|
||||
import { useStore } from '@app/state/store'
|
||||
import colors from '@app/styles/colors'
|
||||
import font from '@app/styles/font'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
import { useAtomValue } from 'jotai/utils'
|
||||
import React from 'react'
|
||||
import { StyleSheet, Text, useWindowDimensions, View } from 'react-native'
|
||||
|
||||
@@ -53,11 +52,11 @@ const AlbumListRenderItem: React.FC<{
|
||||
)
|
||||
|
||||
const AlbumsList = () => {
|
||||
const list = useAtomValue(albumListAtom)
|
||||
const updating = useAtomValue(albumListUpdatingAtom)
|
||||
const updateList = useUpdateAlbumList()
|
||||
const list = useStore(selectMusic.albums)
|
||||
const updating = useStore(selectMusic.albumsUpdating)
|
||||
const updateList = useStore(selectMusic.fetchAlbums)
|
||||
|
||||
useActiveListRefresh(list, updateList)
|
||||
useActiveListRefresh2(updateList)
|
||||
|
||||
const layout = useWindowDimensions()
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import GradientFlatList from '@app/components/GradientFlatList'
|
||||
import ListItem from '@app/components/ListItem'
|
||||
import { useUpdateArtists } from '@app/hooks/music'
|
||||
import { useActiveListRefresh } from '@app/hooks/server'
|
||||
import { useActiveListRefresh2 } from '@app/hooks/server'
|
||||
import { Artist } from '@app/models/music'
|
||||
import { artistsAtom, artistsUpdatingAtom } from '@app/state/music'
|
||||
import { useAtomValue } from 'jotai/utils'
|
||||
import { selectMusic } from '@app/state/music'
|
||||
import { useStore } from '@app/state/store'
|
||||
import React from 'react'
|
||||
import { StyleSheet } from 'react-native'
|
||||
|
||||
@@ -13,11 +12,11 @@ const ArtistRenderItem: React.FC<{ item: Artist }> = ({ item }) => (
|
||||
)
|
||||
|
||||
const ArtistsList = () => {
|
||||
const artists = useAtomValue(artistsAtom)
|
||||
const updating = useAtomValue(artistsUpdatingAtom)
|
||||
const updateArtists = useUpdateArtists()
|
||||
const artists = useStore(selectMusic.artists)
|
||||
const updating = useStore(selectMusic.artistsUpdating)
|
||||
const updateArtists = useStore(selectMusic.fetchArtists)
|
||||
|
||||
useActiveListRefresh(artists, updateArtists)
|
||||
useActiveListRefresh2(updateArtists)
|
||||
|
||||
return (
|
||||
<GradientFlatList
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import GradientFlatList from '@app/components/GradientFlatList'
|
||||
import ListItem from '@app/components/ListItem'
|
||||
import { useUpdatePlaylists } from '@app/hooks/music'
|
||||
import { useActiveListRefresh } from '@app/hooks/server'
|
||||
import { useActiveListRefresh2 } from '@app/hooks/server'
|
||||
import { PlaylistListItem } from '@app/models/music'
|
||||
import { playlistsAtom, playlistsUpdatingAtom } from '@app/state/music'
|
||||
import { useAtomValue } from 'jotai/utils'
|
||||
import { selectMusic } from '@app/state/music'
|
||||
import { useStore } from '@app/state/store'
|
||||
import React from 'react'
|
||||
import { StyleSheet } from 'react-native'
|
||||
|
||||
@@ -13,11 +12,11 @@ const PlaylistRenderItem: React.FC<{ item: PlaylistListItem }> = ({ item }) => (
|
||||
)
|
||||
|
||||
const PlaylistsList = () => {
|
||||
const playlists = useAtomValue(playlistsAtom)
|
||||
const updating = useAtomValue(playlistsUpdatingAtom)
|
||||
const updatePlaylists = useUpdatePlaylists()
|
||||
const playlists = useStore(selectMusic.playlists)
|
||||
const updating = useStore(selectMusic.playlistsUpdating)
|
||||
const updatePlaylists = useStore(selectMusic.fetchPlaylists)
|
||||
|
||||
useActiveListRefresh(playlists, updatePlaylists)
|
||||
useActiveListRefresh2(updatePlaylists)
|
||||
|
||||
return (
|
||||
<GradientFlatList
|
||||
|
||||
@@ -2,13 +2,13 @@ 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 { useUpdateSearchResults } from '@app/hooks/music'
|
||||
import { useActiveListRefresh2 } from '@app/hooks/server'
|
||||
import { ListableItem, SearchResults, Song } from '@app/models/music'
|
||||
import { searchResultsAtom, searchResultsUpdatingAtom } from '@app/state/music'
|
||||
import { selectMusic } from '@app/state/music'
|
||||
import { useStore } from '@app/state/store'
|
||||
import { useSetQueue } from '@app/state/trackplayer'
|
||||
import colors from '@app/styles/colors'
|
||||
import font from '@app/styles/font'
|
||||
import { useAtomValue } from 'jotai/utils'
|
||||
import debounce from 'lodash.debounce'
|
||||
import React, { useCallback, useMemo, useState } from 'react'
|
||||
import { ActivityIndicator, StatusBar, StyleSheet, TextInput, View } from 'react-native'
|
||||
@@ -61,10 +61,19 @@ const Results = React.memo<{
|
||||
})
|
||||
|
||||
const Search = () => {
|
||||
const updateSearch = useStore(selectMusic.fetchSearchResults)
|
||||
const clearSearch = useStore(selectMusic.clearSearchResults)
|
||||
const updating = useStore(selectMusic.searchResultsUpdating)
|
||||
const results = useStore(selectMusic.searchResults)
|
||||
|
||||
useActiveListRefresh2(
|
||||
useCallback(() => {
|
||||
setText('')
|
||||
clearSearch()
|
||||
}, [clearSearch]),
|
||||
)
|
||||
|
||||
const [text, setText] = useState('')
|
||||
const updateSearch = useUpdateSearchResults()
|
||||
const updating = useAtomValue(searchResultsUpdatingAtom)
|
||||
const results = useAtomValue(searchResultsAtom)
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
const debouncedonUpdateSearch = useMemo(() => debounce(updateSearch, 400), [])
|
||||
|
||||
Reference in New Issue
Block a user