navidrome/ui/src/layout/Layout.jsx
Deluan dab37f6a89 fix(ui): load user libraries on app init so NowPlaying filters correctly
The NowPlaying panel filters entries by the user's accessible libraries via
useSelectedLibraries(). That selector reads userLibraries from the store, but
the data was only fetched by LibrarySelector, which is rendered solely when the
sidebar is open. On first load with the sidebar closed, userLibraries was empty,
so getNowPlaying was called without a musicFolderId and the server returned
entries from all libraries until a later refresh.

Extract the loading logic into a useUserLibraries hook and call it from Layout,
so the libraries are always loaded regardless of sidebar state. LibrarySelector
now reuses the same hook instead of duplicating the fetch.

Signed-off-by: Deluan <deluan@navidrome.org>
2026-06-20 00:11:54 -04:00

43 lines
1.2 KiB
JavaScript

import React, { useCallback } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { Layout as RALayout, toggleSidebar } from 'react-admin'
import { makeStyles } from '@material-ui/core/styles'
import { HotKeys } from 'react-hotkeys'
import Menu from './Menu'
import AppBar from './AppBar'
import Notification from './Notification'
import useCurrentTheme from '../themes/useCurrentTheme'
import { useSearchRefocus, useUserLibraries } from '../common'
const useStyles = makeStyles({
root: { paddingBottom: (props) => (props.addPadding ? '80px' : 0) },
})
const Layout = (props) => {
const theme = useCurrentTheme()
const queue = useSelector((state) => state.player?.queue)
const classes = useStyles({ addPadding: queue.length > 0 })
const dispatch = useDispatch()
useSearchRefocus()
useUserLibraries()
const keyHandlers = {
TOGGLE_MENU: useCallback(() => dispatch(toggleSidebar()), [dispatch]),
}
return (
<HotKeys handlers={keyHandlers}>
<RALayout
{...props}
className={classes.root}
menu={Menu}
appBar={AppBar}
theme={theme}
notification={Notification}
/>
</HotKeys>
)
}
export default Layout