[bugfix]: do not change scroll position when focus changes
This commit is contained in:
parent
5f1d0a3b5e
commit
26102bd70a
1 changed files with 24 additions and 1 deletions
|
@ -60,6 +60,7 @@ export const PlayQueue = forwardRef(({ type }: QueueProps, ref: Ref<any>) => {
|
||||||
const { play } = usePlayerControls();
|
const { play } = usePlayerControls();
|
||||||
const volume = useVolume();
|
const volume = useVolume();
|
||||||
const isFocused = useAppFocus();
|
const isFocused = useAppFocus();
|
||||||
|
const isFocusedRef = useRef<boolean>(isFocused);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (tableRef.current) {
|
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);
|
const onCellContextMenu = useHandleTableContextMenu(LibraryItem.SONG, QUEUE_CONTEXT_MENU_ITEMS);
|
||||||
|
|
||||||
|
|
Reference in a new issue