mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
feat(library): add refresh functionality on LibrarySelector close
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
1 parent
2f9a9cf4fb
commit
5ecad64a3f
2 files changed
+8
-1
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
import { useDataProvider, useTranslate } from 'react-admin'
|
||||
import { useDataProvider, useTranslate, useRefresh } from 'react-admin'
|
||||
import {
|
||||
Box,
|
||||
Chip,
|
||||
@@ -71,6 +71,7 @@ const LibrarySelector = () => {
|
||||
const dispatch = useDispatch()
|
||||
const dataProvider = useDataProvider()
|
||||
const translate = useTranslate()
|
||||
const refresh = useRefresh()
|
||||
const [anchorEl, setAnchorEl] = useState(null)
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
@@ -113,6 +114,7 @@ const LibrarySelector = () => {
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false)
|
||||
refresh()
|
||||
}
|
||||
|
||||
const handleLibraryToggle = (libraryId) => {
|
||||
|
||||
@@ -10,6 +10,7 @@ const mockDataProvider = {
|
||||
getOne: vi.fn(),
|
||||
}
|
||||
const mockIdentity = { username: 'testuser' }
|
||||
const mockRefresh = vi.fn()
|
||||
const mockTranslate = vi.fn((key, options = {}) => {
|
||||
const translations = {
|
||||
'menu.librarySelector.allLibraries': `All Libraries (${options.count || 0})`,
|
||||
@@ -29,6 +30,7 @@ vi.mock('react-admin', () => ({
|
||||
useDataProvider: () => mockDataProvider,
|
||||
useGetIdentity: () => ({ identity: mockIdentity }),
|
||||
useTranslate: () => mockTranslate,
|
||||
useRefresh: () => mockRefresh,
|
||||
}))
|
||||
|
||||
// Mock Material-UI components
|
||||
@@ -458,6 +460,9 @@ describe('LibrarySelector', () => {
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTestId('popper')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
// Should trigger refresh when closing
|
||||
expect(mockRefresh).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should load user libraries on mount', async () => {
|
||||
|
||||
Reference in new issue
Block a user