Browse Source

Update query refetch settings for all list-views

- Prevent refetching during selections to not break uniqueId
master
jeffvli 3 years ago
parent
commit
5248d19dd4
  1. 7
      src/components/library/AlbumView.tsx
  2. 8
      src/components/playlist/PlaylistList.tsx
  3. 10
      src/components/playlist/PlaylistView.tsx
  4. 4
      src/components/shared/ContextMenu.tsx
  5. 7
      src/components/starred/StarredView.tsx

7
src/components/library/AlbumView.tsx

@ -33,6 +33,7 @@ interface AlbumParams {
const AlbumView = ({ ...rest }: any) => {
const dispatch = useAppDispatch();
const multiSelect = useAppSelector((state) => state.multiSelect);
const playQueue = useAppSelector((state) => state.playQueue);
const history = useHistory();
const queryClient = useQueryClient();
@ -40,8 +41,10 @@ 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)
const { isLoading, isError, data, error }: any = useQuery(
['album', albumId],
() => getAlbum(albumId),
{ refetchOnWindowFocus: multiSelect.selected.length < 1 }
);
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, data?.song, [

8
src/components/playlist/PlaylistList.tsx

@ -14,16 +14,20 @@ import { StyledButton, StyledInputGroup } from '../shared/styled';
import { errorMessages, isFailedResponse } from '../../shared/utils';
import { notifyToast } from '../shared/toast';
import { AddPlaylistButton } from '../shared/ToolbarButtons';
import { useAppSelector } from '../../redux/hooks';
const PlaylistList = () => {
const history = useHistory();
const queryClient = useQueryClient();
const multiSelect = useAppSelector((state) => state.multiSelect);
const playlistTriggerRef = useRef<any>();
const [sortBy] = useState('name');
const [newPlaylistName, setNewPlaylistName] = useState('');
const [viewType, setViewType] = useState(settings.getSync('playlistViewType') || 'list');
const { isLoading, isError, data: playlists, error }: any = useQuery(['playlists', sortBy], () =>
getPlaylists(sortBy)
const { isLoading, isError, data: playlists, error }: any = useQuery(
['playlists', sortBy],
() => getPlaylists(sortBy),
{ refetchOnWindowFocus: multiSelect.selected.length < 1 }
);
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, playlists, ['name', 'comment']);

10
src/components/playlist/PlaylistView.tsx

@ -57,7 +57,11 @@ interface PlaylistParams {
}
const PlaylistView = ({ ...rest }) => {
const [isModified, setIsModified] = useState(false);
const dispatch = useAppDispatch();
const playQueue = useAppSelector((state) => state.playQueue);
const multiSelect = useAppSelector((state) => state.multiSelect);
const misc = useAppSelector((state) => state.misc);
const history = useHistory();
const queryClient = useQueryClient();
const editTriggerRef = useRef<any>();
@ -67,7 +71,7 @@ const PlaylistView = ({ ...rest }) => {
['playlist', playlistId],
() => getPlaylist(playlistId),
{
refetchOnWindowFocus: false,
refetchOnWindowFocus: multiSelect.selected.length < 1 || !isModified,
}
);
const [editName, setEditName] = useState('');
@ -75,10 +79,6 @@ const PlaylistView = ({ ...rest }) => {
const [editPublic, setEditPublic] = useState(false);
const [isSubmittingEdit, setIsSubmittingEdit] = useState(false);
const [localPlaylistData, setLocalPlaylistData] = useState(data);
const [isModified, setIsModified] = useState(false);
const playQueue = useAppSelector((state) => state.playQueue);
const multiSelect = useAppSelector((state) => state.multiSelect);
const misc = useAppSelector((state) => state.misc);
const [searchQuery, setSearchQuery] = useState('');
const [recoveryPath, setRecoveryPath] = useState('');
const [needsRecovery, setNeedsRecovery] = useState(false);

4
src/components/shared/ContextMenu.tsx

@ -79,7 +79,9 @@ export const GlobalContextMenu = () => {
const [shouldCreatePlaylist, setShouldCreatePlaylist] = useState(false);
const [newPlaylistName, setNewPlaylistName] = useState('');
const { data: playlists }: any = useQuery(['playlists', 'name'], () => getPlaylists('name'));
const { data: playlists }: any = useQuery(['playlists', 'name'], () => getPlaylists('name'), {
refetchOnWindowFocus: false,
});
const handleAddToQueue = () => {
const entriesByRowIndexAsc = _.orderBy(multiSelect.selected, 'rowIndex', 'asc');

7
src/components/starred/StarredView.tsx

@ -4,7 +4,7 @@ import { useQuery } from 'react-query';
import { Nav } from 'rsuite';
import settings from 'electron-settings';
import useSearchQuery from '../../hooks/useSearchQuery';
import { useAppDispatch } from '../../redux/hooks';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { fixPlayer2Index, setPlayQueueByRowClick } from '../../redux/playQueueSlice';
import {
clearSelected,
@ -24,9 +24,12 @@ import { StyledNavItem } from '../shared/styled';
const StarredView = () => {
const history = useHistory();
const dispatch = useAppDispatch();
const multiSelect = useAppSelector((state) => state.multiSelect);
const [currentPage, setCurrentPage] = useState('Tracks');
const [viewType, setViewType] = useState(settings.getSync('albumViewType') || 'list');
const { isLoading, isError, data, error }: any = useQuery('starred', getStarred);
const { isLoading, isError, data, error }: any = useQuery('starred', getStarred, {
refetchOnWindowFocus: multiSelect.selected.length < 1,
});
const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(
searchQuery,

Loading…
Cancel
Save