diff --git a/src/components/library/AlbumView.tsx b/src/components/library/AlbumView.tsx index 3aecc6c..597d14b 100644 --- a/src/components/library/AlbumView.tsx +++ b/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(); 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, [ diff --git a/src/components/playlist/PlaylistList.tsx b/src/components/playlist/PlaylistList.tsx index 47e76bc..281ee58 100644 --- a/src/components/playlist/PlaylistList.tsx +++ b/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(); 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']); diff --git a/src/components/playlist/PlaylistView.tsx b/src/components/playlist/PlaylistView.tsx index 0841636..6de424a 100644 --- a/src/components/playlist/PlaylistView.tsx +++ b/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(); @@ -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); diff --git a/src/components/shared/ContextMenu.tsx b/src/components/shared/ContextMenu.tsx index 90b498c..ff80a31 100644 --- a/src/components/shared/ContextMenu.tsx +++ b/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'); diff --git a/src/components/starred/StarredView.tsx b/src/components/starred/StarredView.tsx index 36ae205..ea46249 100644 --- a/src/components/starred/StarredView.tsx +++ b/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,