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 AlbumView = ({ ...rest }: any) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const multiSelect = useAppSelector((state) => state.multiSelect);
const playQueue = useAppSelector((state) => state.playQueue); const playQueue = useAppSelector((state) => state.playQueue);
const history = useHistory(); const history = useHistory();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -40,8 +41,10 @@ const AlbumView = ({ ...rest }: any) => {
const { id } = useParams<AlbumParams>(); const { id } = useParams<AlbumParams>();
const albumId = rest.id ? rest.id : id; const albumId = rest.id ? rest.id : id;
const { isLoading, isError, data, error }: any = useQuery(['album', albumId], () => const { isLoading, isError, data, error }: any = useQuery(
getAlbum(albumId) ['album', albumId],
() => getAlbum(albumId),
{ refetchOnWindowFocus: multiSelect.selected.length < 1 }
); );
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, data?.song, [ 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 { errorMessages, isFailedResponse } from '../../shared/utils';
import { notifyToast } from '../shared/toast'; import { notifyToast } from '../shared/toast';
import { AddPlaylistButton } from '../shared/ToolbarButtons'; import { AddPlaylistButton } from '../shared/ToolbarButtons';
import { useAppSelector } from '../../redux/hooks';
const PlaylistList = () => { const PlaylistList = () => {
const history = useHistory(); const history = useHistory();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const multiSelect = useAppSelector((state) => state.multiSelect);
const playlistTriggerRef = useRef<any>(); const playlistTriggerRef = useRef<any>();
const [sortBy] = useState('name'); const [sortBy] = useState('name');
const [newPlaylistName, setNewPlaylistName] = useState(''); const [newPlaylistName, setNewPlaylistName] = useState('');
const [viewType, setViewType] = useState(settings.getSync('playlistViewType') || 'list'); const [viewType, setViewType] = useState(settings.getSync('playlistViewType') || 'list');
const { isLoading, isError, data: playlists, error }: any = useQuery(['playlists', sortBy], () => const { isLoading, isError, data: playlists, error }: any = useQuery(
getPlaylists(sortBy) ['playlists', sortBy],
() => getPlaylists(sortBy),
{ refetchOnWindowFocus: multiSelect.selected.length < 1 }
); );
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery(searchQuery, playlists, ['name', 'comment']); const filteredData = useSearchQuery(searchQuery, playlists, ['name', 'comment']);

10
src/components/playlist/PlaylistView.tsx

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

4
src/components/shared/ContextMenu.tsx

@ -79,7 +79,9 @@ export const GlobalContextMenu = () => {
const [shouldCreatePlaylist, setShouldCreatePlaylist] = useState(false); const [shouldCreatePlaylist, setShouldCreatePlaylist] = useState(false);
const [newPlaylistName, setNewPlaylistName] = useState(''); 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 handleAddToQueue = () => {
const entriesByRowIndexAsc = _.orderBy(multiSelect.selected, 'rowIndex', 'asc'); 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 { Nav } from 'rsuite';
import settings from 'electron-settings'; import settings from 'electron-settings';
import useSearchQuery from '../../hooks/useSearchQuery'; import useSearchQuery from '../../hooks/useSearchQuery';
import { useAppDispatch } from '../../redux/hooks'; import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { fixPlayer2Index, setPlayQueueByRowClick } from '../../redux/playQueueSlice'; import { fixPlayer2Index, setPlayQueueByRowClick } from '../../redux/playQueueSlice';
import { import {
clearSelected, clearSelected,
@ -24,9 +24,12 @@ import { StyledNavItem } from '../shared/styled';
const StarredView = () => { const StarredView = () => {
const history = useHistory(); const history = useHistory();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const multiSelect = useAppSelector((state) => state.multiSelect);
const [currentPage, setCurrentPage] = useState('Tracks'); const [currentPage, setCurrentPage] = useState('Tracks');
const [viewType, setViewType] = useState(settings.getSync('albumViewType') || 'list'); 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 [searchQuery, setSearchQuery] = useState('');
const filteredData = useSearchQuery( const filteredData = useSearchQuery(
searchQuery, searchQuery,

Loading…
Cancel
Save