Browse Source

Fix playlist update

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

6
src/api/jellyfinApi.ts

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

91
src/components/playlist/PlaylistView.tsx

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

Loading…
Cancel
Save