diff --git a/plugins/playlist/src/components/PlaylistEditDialog/PlaylistEditDialog.tsx b/plugins/playlist/src/components/PlaylistEditDialog/PlaylistEditDialog.tsx index 50274a5b8c..7eb44403e3 100644 --- a/plugins/playlist/src/components/PlaylistEditDialog/PlaylistEditDialog.tsx +++ b/plugins/playlist/src/components/PlaylistEditDialog/PlaylistEditDialog.tsx @@ -76,9 +76,7 @@ export const PlaylistEditDialog = ({ const classes = useStyles(); const identityApi = useApi(identityApiRef); const playlistApi = useApi(playlistApiRef); - const playlistPromise = useRef( - playlistApi.getAllPlaylists({ editable: true }), - ); + const playlistPromise = useRef(playlistApi.getAllPlaylists()); const [editingOtherFields, setEditingOtherFields] = useState(false); const { loading: loadingOwnership, value: ownershipRefs } = useAsync(async () => { @@ -86,17 +84,14 @@ export const PlaylistEditDialog = ({ return ownershipEntityRefs; }, []); - const nameIsUnique = async ( - name: string, - isEditing: boolean, - originalName: string, - ) => { + const nameIsUnique = async (name: string, isEditing: boolean) => { const playlists = await playlistPromise.current; - if (!isEditing || name !== originalName) { - return playlists.some(p => p.name === name) - ? 'A playlist with this name already exists' - : true; + if (!isEditing || name !== playlist.name) { + return ( + !playlists.some(p => p.name === name) || + 'A playlist with this name already exists' + ); } return true; @@ -141,8 +136,7 @@ export const PlaylistEditDialog = ({ control={control} rules={{ required: true, - validate: value => - nameIsUnique(value, editingOtherFields, playlist.name), + validate: value => nameIsUnique(value, editingOtherFields), }} render={({ field }) => ( { try { await playlistApi.updatePlaylist({ ...update, id: playlist.id }); setOpenEditDialog(false); + let message = `Updated playlist '${playlist.name}'`; if (update.name !== playlist.name) { - const message = `Updated playlist name '${playlist.name}' to '${update.name}'`; - alertApi.post({ - message, - severity: 'success', - display: 'transient', - }); - } else { - const message = `Updated playlist '${playlist.name}'`; - alertApi.post({ - message, - severity: 'success', - display: 'transient', - }); + message = `Updated playlist name '${playlist.name}' to '${update.name}'`; } + + alertApi.post({ + message, + severity: 'success', + display: 'transient', + }); onUpdate(); } catch (e) { errorApi.post(e);