Browse Source

Fix playlist update

master
jeffvli 3 years ago
committed by Jeff
parent
commit
7f3197787c
  1. 6
      src/api/jellyfinApi.ts
  2. 57
      src/components/playlist/PlaylistView.tsx

6
src/api/jellyfinApi.ts

@ -208,7 +208,7 @@ const normalizeScanStatus = () => {
};
export const getPlaylist = async (options: { id: string }) => {
const { data } = await jellyfinApi.get(`/Items`, {
const { data } = await jellyfinApi.get(`/users/${auth.username}/items/${options.id}`, {
params: {
fields: 'Genres, DateCreated, MediaSources, ChildCount',
ids: options.id,
@ -221,7 +221,7 @@ export const getPlaylist = async (options: { id: string }) => {
});
return {
...normalizePlaylist(data.Items[0]),
...normalizePlaylist(data),
songCount: songData.Items.length,
song: (songData.Items || []).map((entry: any) => normalizeSong(entry)),
};
@ -299,7 +299,7 @@ export const updatePlaylist = async (options: {
Name: options.name,
Overview: options.comment,
DateCreated: options.dateCreated,
Genres: genres, // Required
Genres: genres || [], // Required
Tags: [], // Required
PremiereDate: null, // Required
ProviderIds: {}, // Required

57
src/components/playlist/PlaylistView.tsx

@ -130,10 +130,10 @@ const PlaylistView = ({ ...rest }) => {
useEffect(() => {
// Set the local playlist data on any changes
dispatch(setPlaylistData(data?.song));
setEditName(data?.title);
setEditDescription(data?.comment);
setEditPublic(data?.public);
dispatch(setPlaylistData(data?.song || []));
setEditName(data?.title || '');
setEditDescription(data?.comment || '');
setEditPublic(data?.public || false);
}, [data, dispatch]);
useEffect(() => {
@ -310,6 +310,7 @@ const PlaylistView = ({ ...rest }) => {
id: newPlaylistId,
name: data.title,
dateCreated: data.created,
comment: data.comment,
genres: data.genres,
},
});
@ -326,6 +327,9 @@ const PlaylistView = ({ ...rest }) => {
const handleEdit = async () => {
setIsSubmittingEdit(true);
if (config.serverType === Server.Subsonic) {
try {
const res = await apiController({
serverType: config.serverType,
endpoint: 'updatePlaylist',
@ -335,6 +339,7 @@ const PlaylistView = ({ ...rest }) => {
id: data.id,
name: editName,
comment: editDescription,
genres: data.genres,
isPublic: editPublic,
}
: null,
@ -344,11 +349,41 @@ const PlaylistView = ({ ...rest }) => {
notifyToast('error', errorMessages(res)[0]);
} else {
queryClient.setQueryData(['playlist', playlistId], (oldData: any) => {
return { ...oldData, name: editName, comment: editDescription, public: editPublic };
return { ...oldData, title: editName, comment: editDescription, public: editPublic };
});
}
} catch {
notifyToast('error', 'Error saving playlist');
} finally {
setIsSubmittingEdit(false);
}
}
if (config.serverType === Server.Jellyfin) {
try {
apiController({
serverType: config.serverType,
endpoint: 'updatePlaylist',
args: {
id: data.id,
name: editName,
comment: editDescription,
genres: data.genres,
isPublic: editPublic,
},
});
} catch {
notifyToast('error', 'Error saving playlist');
} finally {
setIsSubmittingEdit(false);
}
notifyToast('success', 'Saved playlist');
queryClient.setQueryData(['playlist', playlistId], (oldData: any) => {
return { ...oldData, title: editName, comment: editDescription, public: editPublic };
});
}
editTriggerRef.current.close();
};
@ -370,14 +405,6 @@ const PlaylistView = ({ ...rest }) => {
}
};
// const handleSaveJf = async () => {
// const { id: newPlaylistId } = await apiController({
// serverType: config.serverType,
// endpoint: 'createPlaylist',
// args: { name: data.title },
// });
// };
const handleDragEnd = () => {
if (multiSelect.isDragging) {
dispatch(
@ -575,10 +602,10 @@ const PlaylistView = ({ ...rest }) => {
defaultChecked={editPublic}
value={editPublic}
onChange={(_v: any, e: boolean) => setEditPublic(e)}
disabled={config.serverType === Server.Jellyfin}
>
Public
</StyledCheckbox>
<br />
<StyledButton
size="md"
type="submit"
@ -588,7 +615,7 @@ const PlaylistView = ({ ...rest }) => {
onClick={handleEdit}
appearance="primary"
>
Edit
Save
</StyledButton>
</Form>
</StyledPopover>

Loading…
Cancel
Save