mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Refactor all api instances in components
This commit is contained in:
parent
bdd023fde3
commit
314bd766df
56 changed files with 879 additions and 755 deletions
|
|
@ -5,7 +5,7 @@ import { Variants, motion } from 'framer-motion';
|
|||
import { RiArrowDownSLine, RiSettings3Line } from 'react-icons/ri';
|
||||
import { useLocation } from 'react-router';
|
||||
import styled from 'styled-components';
|
||||
import { Button, Option, Popover, Switch, TableConfigDropdown } from '/@/renderer/components';
|
||||
import { Button, Option, Popover, Switch } from '/@/renderer/components';
|
||||
import {
|
||||
useCurrentSong,
|
||||
useFullScreenPlayerStore,
|
||||
|
|
@ -14,6 +14,7 @@ import {
|
|||
import { useFastAverageColor } from '../../../hooks/use-fast-average-color';
|
||||
import { FullScreenPlayerImage } from '/@/renderer/features/player/components/full-screen-player-image';
|
||||
import { FullScreenPlayerQueue } from '/@/renderer/features/player/components/full-screen-player-queue';
|
||||
import { TableConfigDropdown } from '/@/renderer/components/virtual-table';
|
||||
|
||||
const Container = styled(motion.div)`
|
||||
z-index: 100;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import {
|
|||
import { useRightControls } from '../hooks/use-right-controls';
|
||||
import { PlayerButton } from './player-button';
|
||||
import { LibraryItem, ServerType } from '/@/renderer/api/types';
|
||||
import { useCreateFavorite, useDeleteFavorite, useUpdateRating } from '/@/renderer/features/shared';
|
||||
import { useCreateFavorite, useDeleteFavorite, useSetRating } from '/@/renderer/features/shared';
|
||||
import { Rating } from '/@/renderer/components';
|
||||
import { PlayerbarSlider } from '/@/renderer/features/player/components/playerbar-slider';
|
||||
|
||||
|
|
@ -32,9 +32,9 @@ export const RightControls = () => {
|
|||
const { rightExpanded: isQueueExpanded } = useSidebarStore();
|
||||
const { handleVolumeSlider, handleVolumeWheel, handleMute } = useRightControls();
|
||||
|
||||
const updateRatingMutation = useUpdateRating();
|
||||
const addToFavoritesMutation = useCreateFavorite();
|
||||
const removeFromFavoritesMutation = useDeleteFavorite();
|
||||
const updateRatingMutation = useSetRating({});
|
||||
const addToFavoritesMutation = useCreateFavorite({});
|
||||
const removeFromFavoritesMutation = useDeleteFavorite({});
|
||||
|
||||
const handleAddToFavorites = () => {
|
||||
if (!currentSong) return;
|
||||
|
|
@ -51,11 +51,11 @@ export const RightControls = () => {
|
|||
if (!currentSong) return;
|
||||
|
||||
updateRatingMutation.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
item: [currentSong],
|
||||
rating,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -63,11 +63,11 @@ export const RightControls = () => {
|
|||
if (!currentSong || !rating) return;
|
||||
|
||||
updateRatingMutation.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
item: [currentSong],
|
||||
rating: 0,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '/@/renderer/api/index';
|
||||
import { jfNormalize } from '/@/renderer/api/jellyfin.api';
|
||||
import { JFSong } from '/@/renderer/api/jellyfin.types';
|
||||
import { ndNormalize } from '/@/renderer/api/navidrome.api';
|
||||
import { NDSong } from '/@/renderer/api/navidrome.types';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import {
|
||||
useAuthStore,
|
||||
useCurrentServer,
|
||||
usePlayerControls,
|
||||
usePlayerStore,
|
||||
} from '/@/renderer/store';
|
||||
import { useCurrentServer, usePlayerControls, usePlayerStore } from '/@/renderer/store';
|
||||
import { usePlayerType } from '/@/renderer/store/settings.store';
|
||||
import { PlayQueueAddOptions, Play, PlaybackType } from '/@/renderer/types';
|
||||
import { toast } from '/@/renderer/components/toast';
|
||||
import { toast } from '/@/renderer/components/toast/index';
|
||||
import isElectron from 'is-electron';
|
||||
import { nanoid } from 'nanoid/non-secure';
|
||||
import { LibraryItem, SongListSort, SortOrder } from '/@/renderer/api/types';
|
||||
|
|
@ -25,7 +16,6 @@ const mpris = isElectron() && utils?.isLinux() ? window.electron.mpris : null;
|
|||
export const useHandlePlayQueueAdd = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const playerType = usePlayerType();
|
||||
const deviceId = useAuthStore.getState().deviceId;
|
||||
const server = useCurrentServer();
|
||||
const { play } = usePlayerControls();
|
||||
|
||||
|
|
@ -114,9 +104,11 @@ export const useHandlePlayQueueAdd = () => {
|
|||
queryKey,
|
||||
async ({ signal }) =>
|
||||
api.controller.getPlaylistSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
server,
|
||||
signal,
|
||||
}),
|
||||
{
|
||||
cacheTime: 1000 * 60,
|
||||
|
|
@ -128,9 +120,11 @@ export const useHandlePlayQueueAdd = () => {
|
|||
queryKey,
|
||||
async ({ signal }) =>
|
||||
api.controller.getSongList({
|
||||
apiClientProps: {
|
||||
server,
|
||||
signal,
|
||||
},
|
||||
query: queryFilter,
|
||||
server,
|
||||
signal,
|
||||
}),
|
||||
{
|
||||
cacheTime: 1000 * 60,
|
||||
|
|
@ -147,20 +141,7 @@ export const useHandlePlayQueueAdd = () => {
|
|||
|
||||
if (!songsList) return toast.warn({ message: 'No songs found' });
|
||||
|
||||
switch (server?.type) {
|
||||
case 'jellyfin':
|
||||
songs = songsList.items?.map((song) =>
|
||||
jfNormalize.song(song as JFSong, server, deviceId),
|
||||
);
|
||||
break;
|
||||
case 'navidrome':
|
||||
songs = songsList.items?.map((song) =>
|
||||
ndNormalize.song(song as NDSong, server, deviceId),
|
||||
);
|
||||
break;
|
||||
case 'subsonic':
|
||||
break;
|
||||
}
|
||||
songs = songsList.items?.map((song) => ({ ...song, uniqueId: nanoid() }));
|
||||
} else if (options.byData) {
|
||||
songs = options.byData.map((song) => ({ ...song, uniqueId: nanoid() }));
|
||||
}
|
||||
|
|
@ -207,7 +188,7 @@ export const useHandlePlayQueueAdd = () => {
|
|||
|
||||
return null;
|
||||
},
|
||||
[deviceId, play, playerType, queryClient, server],
|
||||
[play, playerType, queryClient, server],
|
||||
);
|
||||
|
||||
return handlePlayQueueAdd;
|
||||
|
|
|
|||
|
|
@ -67,13 +67,13 @@ export const useScrobble = () => {
|
|||
currentSong?.serverType === ServerType.JELLYFIN ? currentTime * 1e7 : undefined;
|
||||
|
||||
sendScrobble.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
event: 'timeupdate',
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
},
|
||||
[isScrobbleEnabled, sendScrobble],
|
||||
|
|
@ -110,12 +110,12 @@ export const useScrobble = () => {
|
|||
previousSong?.serverType === ServerType.JELLYFIN ? previousSongTime * 1e7 : undefined;
|
||||
|
||||
sendScrobble.mutate({
|
||||
_serverId: previousSong?.serverId,
|
||||
query: {
|
||||
id: previousSong.id,
|
||||
position,
|
||||
submission: true,
|
||||
},
|
||||
serverId: previousSong?.serverId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -130,13 +130,13 @@ export const useScrobble = () => {
|
|||
// Send start scrobble when song changes and the new song is playing
|
||||
if (status === PlayerStatus.PLAYING && currentSong?.id) {
|
||||
sendScrobble.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
event: 'start',
|
||||
id: currentSong.id,
|
||||
position: 0,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
|
|
@ -175,13 +175,13 @@ export const useScrobble = () => {
|
|||
// Whenever the player is restarted, send a 'start' scrobble
|
||||
if (status === PlayerStatus.PLAYING) {
|
||||
sendScrobble.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
event: 'unpause',
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
|
|
@ -194,13 +194,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({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
event: 'pause',
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
if (progressIntervalId.current) {
|
||||
|
|
@ -217,11 +217,11 @@ export const useScrobble = () => {
|
|||
|
||||
if (!isCurrentSongScrobbled && shouldSubmitScrobble) {
|
||||
sendScrobble.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
id: currentSong.id,
|
||||
submission: true,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
|
||||
setIsCurrentSongScrobbled(true);
|
||||
|
|
@ -261,24 +261,24 @@ export const useScrobble = () => {
|
|||
|
||||
if (!isCurrentSongScrobbled && shouldSubmitScrobble) {
|
||||
sendScrobble.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
id: currentSong.id,
|
||||
position,
|
||||
submission: true,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
}
|
||||
|
||||
if (currentSong?.serverType === ServerType.JELLYFIN) {
|
||||
sendScrobble.mutate({
|
||||
_serverId: currentSong?.serverId,
|
||||
query: {
|
||||
event: 'start',
|
||||
id: currentSong.id,
|
||||
position: 0,
|
||||
submission: false,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue