mirror of
https://github.com/Sonarr/Sonarr
synced 2026-05-09 05:40:53 +02:00
Prevent duplicating providers when adding a new provider
This commit is contained in:
parent
5e5f1835f5
commit
536d292838
1 changed files with 9 additions and 5 deletions
|
|
@ -122,13 +122,17 @@ export const useSaveProviderSettings = <T extends ModelBase>(
|
|||
},
|
||||
onSuccess: (updatedSettings: T) => {
|
||||
queryClient.setQueryData<T[]>([path], (oldData = []) => {
|
||||
if (id) {
|
||||
return oldData.map((item) =>
|
||||
item.id === updatedSettings.id ? updatedSettings : item
|
||||
);
|
||||
const existingIndex = oldData.findIndex(
|
||||
(item) => item.id === updatedSettings.id
|
||||
);
|
||||
|
||||
if (existingIndex === -1) {
|
||||
return [...oldData, updatedSettings];
|
||||
}
|
||||
|
||||
return [...oldData, updatedSettings];
|
||||
return oldData.map((item) =>
|
||||
item.id === updatedSettings.id ? updatedSettings : item
|
||||
);
|
||||
});
|
||||
onSuccess?.(updatedSettings);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue