Browse Source

Add star/unstar

master
jeffvli 3 years ago
committed by Jeff
parent
commit
0337cf56c6
  1. 6
      src/api/controller.ts
  2. 12
      src/api/jellyfinApi.ts
  3. 4
      src/components/dashboard/Dashboard.tsx
  4. 4
      src/components/library/AlbumList.tsx
  5. 6
      src/components/library/AlbumView.tsx
  6. 4
      src/components/library/ArtistList.tsx
  7. 10
      src/components/library/ArtistView.tsx
  8. 4
      src/components/library/FolderList.tsx
  9. 4
      src/components/player/NowPlayingMiniView.tsx
  10. 6
      src/components/player/NowPlayingView.tsx
  11. 11
      src/components/player/PlayerBar.tsx
  12. 4
      src/components/playlist/PlaylistView.tsx
  13. 12
      src/components/search/SearchView.tsx
  14. 6
      src/components/starred/StarredView.tsx

6
src/api/controller.ts

@ -42,6 +42,8 @@ import {
getPlaylists as jfGetPlaylists,
getRandomSongs as jfGetRandomSongs,
getStarred as jfGetStarred,
star as jfStar,
unstar as jfUnstar,
} from './jellyfinApi';
import { APIEndpoints, ServerType } from '../types';
@ -58,8 +60,8 @@ const endpoints = [
{ id: 'getArtistSongs', endpoint: { subsonic: getArtistSongs, jellyfin: jfGetArtistSongs } },
{ id: 'startScan', endpoint: { subsonic: startScan, jellyfin: undefined } },
{ id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } },
{ id: 'star', endpoint: { subsonic: star, jellyfin: undefined } },
{ id: 'unstar', endpoint: { subsonic: unstar, jellyfin: undefined } },
{ id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } },
{ id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } },
{ id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } },
{ id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } },
{ id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } },

12
src/api/jellyfinApi.ts

@ -107,7 +107,7 @@ const normalizeSong = (item: any) => {
created: item.DateCreated,
streamUrl: getStreamUrl(item.Id),
image: getCoverArtUrl(item, 150),
starred: item.UserData.isFavorite ? 'true' : undefined,
starred: item.UserData && item.UserData.IsFavorite ? 'true' : undefined,
type: Item.Music,
uniqueId: nanoid(),
};
@ -377,3 +377,13 @@ export const getStarred = async () => {
artist: (artistData.Items || []).map((entry: any) => normalizeArtist(entry)),
};
};
export const star = async (options: { id: string }) => {
const { data } = await jellyfinApi.post(`/users/${auth.username}/favoriteitems/${options.id}`);
return data;
};
export const unstar = async (options: { id: string }) => {
const { data } = await jellyfinApi.delete(`/users/${auth.username}/favoriteitems/${options.id}`);
return data;
};

4
src/components/dashboard/Dashboard.tsx

@ -84,7 +84,7 @@ const Dashboard = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
dispatch(setStar({ id: [rowData.id], type: 'star' }));
queryClient.setQueryData(['recentAlbums', musicFolder], (oldData: any) => {
@ -123,7 +123,7 @@ const Dashboard = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
dispatch(setStar({ id: [rowData.id], type: 'unstar' }));
queryClient.setQueryData(['recentAlbums', musicFolder], (oldData: any) => {

4
src/components/library/AlbumList.tsx

@ -156,7 +156,7 @@ const AlbumList = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['albumList', album.active.filter, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id }));
@ -170,7 +170,7 @@ const AlbumList = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['albumList', album.active.filter, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id }));

6
src/components/library/AlbumView.tsx

@ -150,7 +150,7 @@ const AlbumView = ({ ...rest }: any) => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: data.id, type: 'album' } : null,
args: { id: data.id, type: 'album' },
});
queryClient.setQueryData(['album', id], { ...data, starred: Date.now() });
} else {
@ -168,7 +168,7 @@ const AlbumView = ({ ...rest }: any) => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'star' }));
queryClient.setQueryData(['album', id], (oldData: any) => {
@ -183,7 +183,7 @@ const AlbumView = ({ ...rest }: any) => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'unstar' }));
queryClient.setQueryData(['album', id], (oldData: any) => {

4
src/components/library/ArtistList.tsx

@ -88,7 +88,7 @@ const ArtistList = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null,
args: { id: rowData.id, type: 'artist' },
});
queryClient.setQueryData(['artistList', musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id }));
@ -102,7 +102,7 @@ const ArtistList = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null,
args: { id: rowData.id, type: 'artist' },
});
queryClient.setQueryData(['artistList', musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id }));

10
src/components/library/ArtistView.tsx

@ -46,7 +46,7 @@ import { StyledButton, StyledPopover, StyledTag } from '../shared/styled';
import { setStatus } from '../../redux/playerSlice';
import { GradientBackground, PageHeaderSubtitleDataLine } from '../layout/styled';
import { apiController } from '../../api/controller';
import { Artist, GenericItem, Server } from '../../types';
import { Artist, GenericItem } from '../../types';
const fac = new FastAverageColor();
@ -106,14 +106,14 @@ const ArtistView = ({ ...rest }: any) => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: data.id, type: 'artist' } : null,
args: { id: data.id, type: 'artist' },
});
queryClient.setQueryData(['artist', artistId], { ...data, starred: Date.now() });
} else {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: data.id, type: 'artist' } : null,
args: { id: data.id, type: 'artist' },
});
queryClient.setQueryData(['artist', artistId], { ...data, starred: undefined });
}
@ -162,7 +162,7 @@ const ArtistView = ({ ...rest }: any) => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['artist', artistId], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData?.album, { id: rowData.id }));
@ -176,7 +176,7 @@ const ArtistView = ({ ...rest }: any) => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['artist', artistId], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData?.album, { id: rowData.id }));

4
src/components/library/FolderList.tsx

@ -118,7 +118,7 @@ const FolderList = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['folder', folder.currentViewedFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.child, { id: rowData.id }));
@ -132,7 +132,7 @@ const FolderList = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['folder', folder.currentViewedFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.child, { id: rowData.id }));

4
src/components/player/NowPlayingMiniView.tsx

@ -265,14 +265,14 @@ const NowPlayingMiniView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'star' }));
} else {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'unstar' }));
}

6
src/components/player/NowPlayingView.tsx

@ -60,7 +60,7 @@ import {
} from '../../shared/utils';
import { notifyToast } from '../shared/toast';
import { apiController } from '../../api/controller';
import { Server, Song } from '../../types';
import { Song } from '../../types';
const NowPlayingView = () => {
const tableRef = useRef<any>();
@ -275,14 +275,14 @@ const NowPlayingView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'star' }));
} else {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'unstar' }));
}

11
src/components/player/PlayerBar.tsx

@ -35,7 +35,6 @@ import { CoverArtWrapper } from '../layout/styled';
import { getCurrentEntryList, isCached } from '../../shared/utils';
import { StyledPopover } from '../shared/styled';
import { apiController } from '../../api/controller';
import { Server } from '../../types';
const PlayerBar = () => {
const queryClient = useQueryClient();
@ -278,10 +277,7 @@ const PlayerBar = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args:
config.serverType === Server.Subsonic
? { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' }
: null,
args: { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' },
});
dispatch(
setStar({
@ -293,10 +289,7 @@ const PlayerBar = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args:
config.serverType === Server.Subsonic
? { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' }
: null,
args: { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' },
});
dispatch(
setStar({

4
src/components/playlist/PlaylistView.tsx

@ -352,7 +352,7 @@ const PlaylistView = ({ ...rest }) => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'star' }));
dispatch(setPlaylistStar({ id: [rowData.id], type: 'star' }));
@ -369,7 +369,7 @@ const PlaylistView = ({ ...rest }) => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'unstar' }));
dispatch(setPlaylistStar({ id: [rowData.id], type: 'unstar' }));

12
src/components/search/SearchView.tsx

@ -94,7 +94,7 @@ const SearchView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.song, { id: rowData.id }));
@ -108,7 +108,7 @@ const SearchView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.song, { id: rowData.id }));
@ -126,7 +126,7 @@ const SearchView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null,
args: { id: rowData.id, type: 'artist' },
});
queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.artist, { id: rowData.id }));
@ -140,7 +140,7 @@ const SearchView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.artist, { id: rowData.id }));
@ -158,7 +158,7 @@ const SearchView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'star',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null,
args: { id: rowData.id, type: 'artist' },
});
queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.album, { id: rowData.id }));
@ -172,7 +172,7 @@ const SearchView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => {
const starredIndices = _.keys(_.pickBy(oldData.album, { id: rowData.id }));

6
src/components/starred/StarredView.tsx

@ -106,7 +106,7 @@ const StarredView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null,
args: { id: rowData.id, type: 'music' },
});
dispatch(setStar({ id: [rowData.id], type: 'unstar' }));
await queryClient.refetchQueries(['starred', musicFolder], {
@ -118,7 +118,7 @@ const StarredView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null,
args: { id: rowData.id, type: 'album' },
});
await queryClient.refetchQueries(['starred', musicFolder], {
active: true,
@ -129,7 +129,7 @@ const StarredView = () => {
await apiController({
serverType: config.serverType,
endpoint: 'unstar',
args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null,
args: { id: rowData.id, type: 'artist' },
});
await queryClient.refetchQueries(['starred', musicFolder], {
active: true,

Loading…
Cancel
Save