Review changes done reduce code size
Signed-off-by: AmbrishRamachandiran <ambrish.r@infosys.com>
This commit is contained in:
@@ -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 }) => (
|
||||
<TextField
|
||||
|
||||
@@ -100,21 +100,16 @@ export const PlaylistHeader = ({ playlist, onUpdate }: PlaylistHeaderProps) => {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user