[bugfix]: do not change scroll position when focus changes

This commit is contained in:
Kendall Garner 2024-01-24 21:05:26 -08:00
parent 5f1d0a3b5e
commit 26102bd70a
No known key found for this signature in database
GPG Key ID: 18D2767419676C87

View File

@ -60,6 +60,7 @@ export const PlayQueue = forwardRef(({ type }: QueueProps, ref: Ref<any>) => {
const { play } = usePlayerControls();
const volume = useVolume();
const isFocused = useAppFocus();
const isFocusedRef = useRef<boolean>(isFocused);
useEffect(() => {
if (tableRef.current) {
@ -211,7 +212,29 @@ export const PlayQueue = forwardRef(({ type }: QueueProps, ref: Ref<any>) => {
}
}
}
}, [currentSong, previousSong, tableConfig.followCurrentSong, status, isFocused]);
}, [currentSong, previousSong, tableConfig.followCurrentSong, status]);
// As a separate rule, update the current row when focus changes. This is
// to prevent queue scrolling when the application loses and then gains focus.
// The body should only fire when focus changes, even though it depends on current song
useEffect(() => {
if (isFocused !== isFocusedRef.current && tableRef?.current) {
const { api, columnApi } = tableRef.current;
if (api == null || columnApi == null) {
return;
}
const currentNode = currentSong?.uniqueId
? api.getRowNode(currentSong.uniqueId)
: undefined;
if (currentNode) {
api.redrawRows({ rowNodes: [currentNode] });
}
isFocusedRef.current = isFocused;
}
}, [currentSong, isFocused]);
const onCellContextMenu = useHandleTableContextMenu(LibraryItem.SONG, QUEUE_CONTEXT_MENU_ITEMS);