navidrome/ui/src/common/useRefreshMetadata.js
Deluan Quintão afb3a2f881
feat(ui): add Refresh Metadata action to the album and artist pages (#6078)
The Refresh Metadata action was only reachable from the Album and Artist context menus, so it could not be triggered from AlbumShow or ArtistShow. This adds an icon-only button, with a tooltip, to the action toolbar on both detail pages. Like the menu entry, it is only rendered for admins.

The button is built on react-admin's Button rather than a plain IconButton: the surrounding toolbars use the former, so the theme colour and the icon-only swap at the xs breakpoint are inherited instead of restated. The dataProvider call and its two notifications move into a new useRefreshMetadata hook, which ContextMenus now shares, keeping a single copy of that logic.
2026-09-02 23:29:31 -04:00

17 lines
463 B
JavaScript

import { useCallback } from 'react'
import { useDataProvider, useNotify } from 'react-admin'
export const useRefreshMetadata = () => {
const dataProvider = useDataProvider()
const notify = useNotify()
return useCallback(
(resource, id) =>
dataProvider
.refreshMetadata(resource, id)
.then(() => notify('message.metadataRefreshStarted'))
.catch(() => notify('ra.page.error', 'warning')),
[dataProvider, notify],
)
}