fix(ui): keep the NowPlayingPanel badge in sync.

Introduced a new event, EVENT_STREAM_RECONNECTED, to track the last
timestamp of stream reconnections. This change updates the activity
reducer to handle the new event and modifies the NowPlayingPanel to
refresh data based on server and stream status.

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan
2025-06-29 11:35:10 -04:00
parent dce7705999
commit 4f83987840
6 changed files with 197 additions and 22 deletions
+21 -6
View File
@@ -245,6 +245,12 @@ NowPlayingList.propTypes = {
const NowPlayingPanel = () => {
const dispatch = useDispatch()
const count = useSelector((state) => state.activity.nowPlayingCount)
const streamReconnected = useSelector(
(state) => state.activity.streamReconnected,
)
const serverUp = useSelector(
(state) => !!state.activity.serverStart.startTime,
)
const translate = useTranslate()
const notify = useNotify()
const theme = useTheme()
@@ -301,23 +307,32 @@ const NowPlayingPanel = () => {
[dispatch, notify],
)
// Initialize count and entries on mount
// Initialize count and entries on mount, and refresh on server/stream changes
useEffect(() => {
fetchList()
}, [fetchList])
if (serverUp) fetchList()
}, [fetchList, serverUp, streamReconnected])
// Refresh when count changes from WebSocket events (if panel is open)
useEffect(() => {
if (open) fetchList()
}, [count, open, fetchList])
if (open && serverUp) fetchList()
}, [count, open, fetchList, serverUp])
// Periodic refresh when panel is open (10 seconds)
useInterval(
() => {
if (open) fetchList()
if (open && serverUp) fetchList()
},
open ? 10000 : null,
)
// Periodic refresh when panel is closed (60 seconds) to keep badge accurate
useInterval(
() => {
if (!open && serverUp) fetchList()
},
!open ? 60000 : null,
)
return (
<div>
<NowPlayingButton count={count} onClick={handleMenuOpen} />