mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
feat(plugins): update config handling in PluginShow to track last record state
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
cef1d339a3
commit
dfaf22248a
@ -41,6 +41,7 @@ vi.mock('../common', async () => {
|
||||
SimpleList: ({ primaryText, secondaryText }) => (
|
||||
<div data-testid="simple-list" />
|
||||
),
|
||||
useResourceRefresh: vi.fn(),
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ const PluginShowLayout = () => {
|
||||
|
||||
const [configPairs, setConfigPairs] = useState([])
|
||||
const [isDirty, setIsDirty] = useState(false)
|
||||
const [configInitialized, setConfigInitialized] = useState(false)
|
||||
const [lastRecordConfig, setLastRecordConfig] = useState(null)
|
||||
|
||||
// Convert JSON config to key-value pairs
|
||||
const jsonToPairs = useCallback((jsonString) => {
|
||||
@ -65,13 +65,14 @@ const PluginShowLayout = () => {
|
||||
return JSON.stringify(obj)
|
||||
}, [])
|
||||
|
||||
// Initialize config when record loads
|
||||
// Initialize/update config when record loads or changes (e.g., from SSE refresh)
|
||||
React.useEffect(() => {
|
||||
if (record && !configInitialized) {
|
||||
setConfigPairs(jsonToPairs(record.config || ''))
|
||||
setConfigInitialized(true)
|
||||
const recordConfig = record?.config || ''
|
||||
if (record && recordConfig !== lastRecordConfig && !isDirty) {
|
||||
setConfigPairs(jsonToPairs(recordConfig))
|
||||
setLastRecordConfig(recordConfig)
|
||||
}
|
||||
}, [record, configInitialized, jsonToPairs])
|
||||
}, [record, lastRecordConfig, isDirty, jsonToPairs])
|
||||
|
||||
const handleConfigPairsChange = useCallback(
|
||||
(newPairs) => {
|
||||
@ -93,7 +94,7 @@ const PluginShowLayout = () => {
|
||||
onSuccess: () => {
|
||||
refresh()
|
||||
setIsDirty(false)
|
||||
setConfigInitialized(false) // Reset to reinitialize from server
|
||||
setLastRecordConfig(null) // Reset to reinitialize from server
|
||||
notify('resources.plugin.notifications.updated', 'info')
|
||||
},
|
||||
onFailure: (err) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user