refactor api controller to internalize server fetch

This commit is contained in:
jeffvli
2025-11-02 21:56:35 -08:00
parent 8dbaec3943
commit c7a473d864
79 changed files with 904 additions and 399 deletions
@@ -39,7 +39,6 @@ import { useDeleteFavorite } from '/@/renderer/features/shared/mutations/delete-
import { useSetRating } from '/@/renderer/features/shared/mutations/set-rating-mutation';
import { AppRoute } from '/@/renderer/router/routes';
import {
getServerById,
useAuthStore,
useCurrentServer,
usePlayerStore,
@@ -260,7 +259,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
const handleDeletePlaylist = useCallback(() => {
for (const item of ctx.data) {
deletePlaylistMutation?.mutate(
{ query: { id: item.id }, serverId: item.serverId },
{ apiClientProps: { serverId: item.serverId }, query: { id: item.id } },
{
onError: (err) => {
toast.error({
@@ -330,11 +329,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
createFavoriteMutation.mutate(
{
apiClientProps: { serverId },
query: {
id: items.map((item) => item.id),
type: ctx.type,
},
serverId,
},
{
onError: (err) => {
@@ -369,11 +368,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
createFavoriteMutation.mutate(
{
apiClientProps: { serverId },
query: {
id: items.map((item: AnyLibraryItem) => item.id),
type: ctx.type,
},
serverId,
},
{
onError: (err) => {
@@ -408,11 +407,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
const idsToUnfavorite = nodesByServerId[serverId].map((node) => node.data.id);
deleteFavoriteMutation.mutate(
{
apiClientProps: { serverId },
query: {
id: idsToUnfavorite,
type: ctx.type,
},
serverId,
},
{
onSuccess: () => {
@@ -441,11 +440,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
(item: AnyLibraryItem) => item.id,
);
deleteFavoriteMutation.mutate({
apiClientProps: { serverId },
query: {
id: idsToUnfavorite,
type: ctx.type,
},
serverId,
});
}
}
@@ -529,11 +528,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
const confirm = () => {
removeFromPlaylistMutation.mutate(
{
apiClientProps: { serverId: ctx.data?.[0]?.serverId },
query: {
id: ctx.context.playlistId,
songId: songId || [],
},
serverId: ctx.data?.[0]?.serverId,
},
{
onError: (err) => {
@@ -604,11 +603,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
updateRatingMutation.mutate(
{
apiClientProps: { serverId },
query: {
item: items,
rating: ratingToSet,
},
serverId,
},
{
onSuccess: () => {
@@ -719,7 +718,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
const item = ctx.data[0];
const songs = await controller.getSimilarSongs({
apiClientProps: {
server: getServerById(item.serverId),
serverId: item.serverId,
signal: undefined,
},
query: { albumArtistIds: item.albumArtistIds, songId: item.id },
@@ -732,7 +731,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
const handleDownload = useCallback(() => {
const item = ctx.data[0];
const url = api.controller.getDownloadUrl({
apiClientProps: { server },
apiClientProps: { serverId: item.serverId },
query: { id: item.id },
});
@@ -741,7 +740,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
} else {
window.open(url, '_blank');
}
}, [ctx.data, server]);
}, [ctx.data]);
const handleGoToAlbum = useCallback(() => {
const item = ctx.data[0];