mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-28 14:17:10 +01:00
feat(library): add refresh functionality on LibrarySelector close
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
2f9a9cf4fb
commit
5ecad64a3f
2 changed files with 8 additions and 1 deletions
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue