mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 04:51:06 +02:00
refactor api controller to internalize server fetch
This commit is contained in:
@@ -62,11 +62,11 @@ export const RightControls = () => {
|
||||
if (!song?.id) return;
|
||||
|
||||
addToFavoritesMutation.mutate({
|
||||
apiClientProps: { serverId: song?.serverId || '' },
|
||||
query: {
|
||||
id: [song.id],
|
||||
type: LibraryItem.SONG,
|
||||
},
|
||||
serverId: song?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -74,11 +74,11 @@ export const RightControls = () => {
|
||||
if (!currentSong) return;
|
||||
|
||||
updateRatingMutation.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
item: [currentSong],
|
||||
rating,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -86,11 +86,11 @@ export const RightControls = () => {
|
||||
if (!song?.id) return;
|
||||
|
||||
removeFromFavoritesMutation.mutate({
|
||||
apiClientProps: { serverId: song?.serverId || '' },
|
||||
query: {
|
||||
id: [song.id],
|
||||
type: LibraryItem.SONG,
|
||||
},
|
||||
serverId: song?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -163,16 +163,17 @@ export const RightControls = () => {
|
||||
remote.requestFavorite((_event, { favorite, id, serverId }) => {
|
||||
const mutator = favorite ? addToFavoritesMutation : removeFromFavoritesMutation;
|
||||
mutator.mutate({
|
||||
apiClientProps: { serverId },
|
||||
query: {
|
||||
id: [id],
|
||||
type: LibraryItem.SONG,
|
||||
},
|
||||
serverId,
|
||||
});
|
||||
});
|
||||
|
||||
remote.requestRating((_event, { id, rating, serverId }) => {
|
||||
updateRatingMutation.mutate({
|
||||
apiClientProps: { serverId },
|
||||
query: {
|
||||
item: [
|
||||
{
|
||||
@@ -183,7 +184,6 @@ export const RightControls = () => {
|
||||
],
|
||||
rating,
|
||||
},
|
||||
serverId,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export const ShuffleAllModal = ({
|
||||
queryFn: ({ signal }) =>
|
||||
api.controller.getRandomSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: {
|
||||
@@ -257,7 +257,7 @@ export const openShuffleAllModal = async (
|
||||
queryFn: ({ signal }) =>
|
||||
api.controller.getGenreList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: {
|
||||
@@ -275,7 +275,7 @@ export const openShuffleAllModal = async (
|
||||
queryFn: ({ signal }) =>
|
||||
api.controller.getMusicFolderList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -39,22 +39,18 @@ export const useMediaSession = ({
|
||||
}
|
||||
|
||||
mediaSession.setActionHandler('nexttrack', () => {
|
||||
console.log('nexttrack');
|
||||
handleNextTrack();
|
||||
});
|
||||
|
||||
mediaSession.setActionHandler('pause', () => {
|
||||
console.log('pause');
|
||||
handlePause();
|
||||
});
|
||||
|
||||
mediaSession.setActionHandler('play', () => {
|
||||
console.log('play');
|
||||
handlePlay();
|
||||
});
|
||||
|
||||
mediaSession.setActionHandler('previoustrack', () => {
|
||||
console.log('previoustrack');
|
||||
handlePrevTrack();
|
||||
});
|
||||
|
||||
|
||||
@@ -75,13 +75,13 @@ export const useScrobble = () => {
|
||||
currentSong?.serverType === ServerType.JELLYFIN ? currentTime * 1e7 : undefined;
|
||||
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
event: 'timeupdate',
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
},
|
||||
[isScrobbleEnabled, isPrivateModeEnabled, sendScrobble],
|
||||
@@ -149,12 +149,12 @@ export const useScrobble = () => {
|
||||
: undefined;
|
||||
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: previousSong?.serverId || '' },
|
||||
query: {
|
||||
id: previousSong.id,
|
||||
position,
|
||||
submission: true,
|
||||
},
|
||||
serverId: previousSong?.serverId,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -173,13 +173,13 @@ export const useScrobble = () => {
|
||||
// Send start scrobble when song changes and the new song is playing
|
||||
if (currentStatus === PlayerStatus.PLAYING && currentSong?.id) {
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
event: 'start',
|
||||
id: currentSong.id,
|
||||
position: 0,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
@@ -228,13 +228,13 @@ export const useScrobble = () => {
|
||||
// Whenever the player is restarted, send a 'start' scrobble
|
||||
if (currentStatus === PlayerStatus.PLAYING) {
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
event: 'unpause',
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
@@ -253,13 +253,13 @@ export const useScrobble = () => {
|
||||
// Jellyfin is the only one that needs to send a 'pause' event to the server
|
||||
} else if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
event: 'pause',
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
if (progressIntervalId.current) {
|
||||
@@ -287,11 +287,11 @@ export const useScrobble = () => {
|
||||
|
||||
if (!isCurrentSongScrobbled && shouldSubmitScrobble) {
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
id: currentSong.id,
|
||||
submission: true,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
setIsCurrentSongScrobbled(true);
|
||||
@@ -332,24 +332,24 @@ export const useScrobble = () => {
|
||||
|
||||
if (!isCurrentSongScrobbled && shouldSubmitScrobble) {
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: true,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
}
|
||||
|
||||
if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
sendScrobble.mutate({
|
||||
apiClientProps: { serverId: currentSong?.serverId || '' },
|
||||
query: {
|
||||
event: 'start',
|
||||
id: currentSong.id,
|
||||
position: 0,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { AxiosError } from 'axios';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||
import { getServerById, useIncrementQueuePlayCount } from '/@/renderer/store';
|
||||
import { useIncrementQueuePlayCount } from '/@/renderer/store';
|
||||
import { usePlayEvent } from '/@/renderer/store/event.store';
|
||||
import { ScrobbleArgs, ScrobbleResponse } from '/@/shared/types/domain-types';
|
||||
|
||||
@@ -11,16 +11,12 @@ export const useSendScrobble = (options?: MutationOptions) => {
|
||||
const incrementPlayCount = useIncrementQueuePlayCount();
|
||||
const sendPlayEvent = usePlayEvent();
|
||||
|
||||
return useMutation<
|
||||
ScrobbleResponse,
|
||||
AxiosError,
|
||||
Omit<ScrobbleArgs, 'apiClientProps' | 'server'>,
|
||||
null
|
||||
>({
|
||||
return useMutation<ScrobbleResponse, AxiosError, ScrobbleArgs, null>({
|
||||
mutationFn: (args) => {
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return api.controller.scrobble({ ...args, apiClientProps: { server } });
|
||||
return api.controller.scrobble({
|
||||
...args,
|
||||
apiClientProps: { serverId: args.apiClientProps.serverId },
|
||||
});
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
// Manually increment the play count for the song in the queue if scrobble was submitted
|
||||
|
||||
@@ -33,7 +33,7 @@ export const getPlaylistSongsById = async (args: {
|
||||
queryFn: async ({ signal }) =>
|
||||
api.controller.getPlaylistSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
@@ -77,7 +77,7 @@ export const getAlbumSongsById = async (args: {
|
||||
queryFn: async ({ signal }) =>
|
||||
api.controller.getSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
@@ -119,7 +119,7 @@ export const getGenreSongsById = async (args: {
|
||||
queryFn: async ({ signal }) =>
|
||||
api.controller.getSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
@@ -161,7 +161,7 @@ export const getAlbumArtistSongsById = async (args: {
|
||||
queryFn: async ({ signal }) =>
|
||||
api.controller.getSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
@@ -196,7 +196,7 @@ export const getArtistSongsById = async (args: {
|
||||
queryFn: async ({ signal }) =>
|
||||
api.controller.getSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
@@ -229,7 +229,7 @@ export const getSongsByQuery = async (args: {
|
||||
queryFn: async ({ signal }) => {
|
||||
return api.controller.getSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
@@ -258,7 +258,7 @@ export const getSongById = async (args: {
|
||||
queryFn: async ({ signal }) =>
|
||||
api.controller.getSongDetail({
|
||||
apiClientProps: {
|
||||
server,
|
||||
serverId: server?.id || '',
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
|
||||
Reference in New Issue
Block a user