Remove unused refetches

This commit is contained in:
jeffvli
2021-10-26 09:22:09 -07:00
committed by Jeff
parent 087f5e38c6
commit 3ceb294f2b
9 changed files with 36 additions and 68 deletions

View File

@@ -28,26 +28,22 @@ const Dashboard = () => {
const { isLoading: isLoadingRecent, data: recentAlbums }: any = useQuery(
['recentAlbums', musicFolder],
() => getAlbums({ type: 'recent', size: 20, musicFolderId: musicFolder }, 250),
{ refetchOnWindowFocus: false }
() => getAlbums({ type: 'recent', size: 20, musicFolderId: musicFolder }, 250)
);
const { isLoading: isLoadingNewest, data: newestAlbums }: any = useQuery(
['newestAlbums', musicFolder],
() => getAlbums({ type: 'newest', size: 20, musicFolderId: musicFolder }, 250),
{ refetchOnWindowFocus: false }
() => getAlbums({ type: 'newest', size: 20, musicFolderId: musicFolder }, 250)
);
const { isLoading: isLoadingRandom, data: randomAlbums }: any = useQuery(
['randomAlbums', musicFolder],
() => getAlbums({ type: 'random', size: 20, musicFolderId: musicFolder }, 250),
{ refetchOnWindowFocus: false }
() => getAlbums({ type: 'random', size: 20, musicFolderId: musicFolder }, 250)
);
const { isLoading: isLoadingFrequent, data: frequentAlbums }: any = useQuery(
['frequentAlbums', musicFolder],
() => getAlbums({ type: 'frequent', size: 20, musicFolderId: musicFolder }, 250),
{ refetchOnWindowFocus: false }
() => getAlbums({ type: 'frequent', size: 20, musicFolderId: musicFolder }, 250)
);
const handleFavorite = async (rowData: any) => {

View File

@@ -65,28 +65,23 @@ const AlbumList = () => {
musicFolderId: musicFolder,
}),
{
refetchOnWindowFocus: false,
cacheTime: 3600000, // Stay in cache for 1 hour
staleTime: Infinity, // Only allow manual refresh
}
);
const { data: genres }: any = useQuery(
['genreList'],
async () => {
const res = await getGenres();
return res.map((genre: any) => {
if (genre.albumCount !== 0) {
return {
label: `${genre.value} (${genre.albumCount})`,
value: genre.value,
role: 'Genre',
};
}
return null;
});
},
{ refetchOnWindowFocus: false }
);
const { data: genres }: any = useQuery(['genreList'], async () => {
const res = await getGenres();
return res.map((genre: any) => {
if (genre.albumCount !== 0) {
return {
label: `${genre.value} (${genre.albumCount})`,
value: genre.value,
role: 'Genre',
};
}
return null;
});
});
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, albums, ['name', 'artist', 'genre', 'year']);

View File

@@ -42,7 +42,6 @@ interface AlbumParams {
const AlbumView = ({ ...rest }: any) => {
const dispatch = useAppDispatch();
const multiSelect = useAppSelector((state) => state.multiSelect);
const playQueue = useAppSelector((state) => state.playQueue);
const misc = useAppSelector((state) => state.misc);
const history = useHistory();
@@ -51,10 +50,8 @@ const AlbumView = ({ ...rest }: any) => {
const { id } = useParams<AlbumParams>();
const albumId = rest.id ? rest.id : id;
const { isLoading, isError, data, error }: any = useQuery(
['album', albumId],
() => getAlbum(albumId),
{ refetchOnWindowFocus: multiSelect.selected.length < 1 }
const { isLoading, isError, data, error }: any = useQuery(['album', albumId], () =>
getAlbum(albumId)
);
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, data?.song, [

View File

@@ -40,7 +40,6 @@ const ArtistList = () => {
['artistList', musicFolder],
() => getArtists({ musicFolderId: musicFolder }),
{
refetchOnWindowFocus: false,
cacheTime: 3600000, // Stay in cache for 1 hour
staleTime: Infinity, // Only allow manual refresh
}

View File

@@ -40,19 +40,13 @@ const FolderList = () => {
const { isLoading, isError, data: indexData, error }: any = useQuery(
['indexes', musicFolder],
() => getIndexes({ musicFolderId: musicFolder }),
{
refetchOnReconnect: false,
refetchOnWindowFocus: false,
}
() => getIndexes({ musicFolderId: musicFolder })
);
const { isLoading: isLoadingFolderData, data: folderData }: any = useQuery(
['folder', folder.currentViewedFolder],
() => getMusicDirectory({ id: folder.currentViewedFolder }),
{
enabled: folder.currentViewedFolder !== '',
refetchOnReconnect: false,
refetchOnWindowFocus: false,
}
);

View File

@@ -71,21 +71,17 @@ const NowPlayingView = () => {
'path',
]);
const { data: genres }: any = useQuery(
['genreList'],
async () => {
const res = await getGenres();
const genresOrderedBySongCount = _.orderBy(res, 'songCount', 'desc');
return genresOrderedBySongCount.map((genre: any) => {
return {
label: `${genre.value} (${genre.songCount})`,
value: genre.value,
role: 'Genre',
};
});
},
{ refetchOnWindowFocus: false }
);
const { data: genres }: any = useQuery(['genreList'], async () => {
const res = await getGenres();
const genresOrderedBySongCount = _.orderBy(res, 'songCount', 'desc');
return genresOrderedBySongCount.map((genre: any) => {
return {
label: `${genre.value} (${genre.songCount})`,
value: genre.value,
role: 'Genre',
};
});
});
useHotkeys(
'del',

View File

@@ -84,10 +84,8 @@ const PlaylistView = ({ ...rest }) => {
const editTriggerRef = useRef<any>();
const { id } = useParams<PlaylistParams>();
const playlistId = rest.id ? rest.id : id;
const { isLoading, isError, data, error }: any = useQuery(
['playlist', playlistId],
() => getPlaylist(playlistId),
{ refetchOnWindowFocus: false }
const { isLoading, isError, data, error }: any = useQuery(['playlist', playlistId], () =>
getPlaylist(playlistId)
);
const [editName, setEditName] = useState('');
const [editDescription, setEditDescription] = useState('');

View File

@@ -109,9 +109,7 @@ export const GlobalContextMenu = () => {
const [newPlaylistName, setNewPlaylistName] = useState('');
const [indexToMoveTo, setIndexToMoveTo] = useState(0);
const { data: playlists }: any = useQuery(['playlists', 'name'], () => getPlaylists('name'), {
refetchOnWindowFocus: false,
});
const { data: playlists }: any = useQuery(['playlists', 'name'], () => getPlaylists('name'));
const handlePlay = async () => {
dispatch(setContextMenu({ show: false }));

View File

@@ -26,7 +26,6 @@ const StarredView = () => {
const history = useHistory();
const dispatch = useAppDispatch();
const queryClient = useQueryClient();
const multiSelect = useAppSelector((state) => state.multiSelect);
const folder = useAppSelector((state) => state.folder);
const favorite = useAppSelector((state) => state.favorite);
const config = useAppSelector((state) => state.config);
@@ -39,12 +38,8 @@ const StarredView = () => {
}
}, [folder]);
const { isLoading, isError, data, error }: any = useQuery(
['starred', musicFolder],
() => getStarred({ musicFolderId: musicFolder }),
{
refetchOnWindowFocus: multiSelect.selected.length < 1,
}
const { isLoading, isError, data, error }: any = useQuery(['starred', musicFolder], () =>
getStarred({ musicFolderId: musicFolder })
);
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(