mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #5085 from grafixeyehero/Convert-played-and-ratingbuttons-to-react
Convert playstatebutton and ratingbuttons to react
This commit is contained in:
commit
3a120011c8
3 changed files with 205 additions and 1 deletions
|
@ -15,6 +15,7 @@ import { getStudiosApi } from '@jellyfin/sdk/lib/utils/api/studios-api';
|
|||
import { getTvShowsApi } from '@jellyfin/sdk/lib/utils/api/tv-shows-api';
|
||||
import { getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api/user-library-api';
|
||||
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||
import { getPlaystateApi } from '@jellyfin/sdk/lib/utils/api/playstate-api';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import datetime from 'scripts/datetime';
|
||||
import globalize from 'scripts/globalize';
|
||||
|
@ -166,7 +167,7 @@ const fetchGetItemsBySuggestionsType = async (
|
|||
response = (
|
||||
await getItemsApi(api).getResumeItems(
|
||||
{
|
||||
userId: user?.Id,
|
||||
userId: user.Id,
|
||||
parentId: parentId ?? undefined,
|
||||
fields: [
|
||||
ItemFields.PrimaryImageAspectRatio,
|
||||
|
@ -617,3 +618,75 @@ export const useGetGroupsUpcomingEpisodes = (parentId: ParentId) => {
|
|||
enabled: !!parentId
|
||||
});
|
||||
};
|
||||
|
||||
interface ToggleFavoriteMutationProp {
|
||||
itemId: string;
|
||||
favoriteState: boolean
|
||||
}
|
||||
|
||||
const fetchUpdateFavoriteStatus = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
itemId: string,
|
||||
favoriteState: boolean
|
||||
) => {
|
||||
const { api, user } = currentApi;
|
||||
if (api && user?.Id) {
|
||||
if (favoriteState) {
|
||||
const response = await getUserLibraryApi(api).unmarkFavoriteItem({
|
||||
userId: user.Id,
|
||||
itemId: itemId
|
||||
});
|
||||
return response.data.IsFavorite;
|
||||
} else {
|
||||
const response = await getUserLibraryApi(api).markFavoriteItem({
|
||||
userId: user.Id,
|
||||
itemId: itemId
|
||||
});
|
||||
return response.data.IsFavorite;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const useToggleFavoriteMutation = () => {
|
||||
const currentApi = useApi();
|
||||
return useMutation({
|
||||
mutationFn: ({ itemId, favoriteState }: ToggleFavoriteMutationProp) =>
|
||||
fetchUpdateFavoriteStatus(currentApi, itemId, favoriteState )
|
||||
});
|
||||
};
|
||||
|
||||
interface TogglePlayedMutationProp {
|
||||
itemId: string;
|
||||
playedState: boolean
|
||||
}
|
||||
|
||||
const fetchUpdatePlayedState = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
itemId: string,
|
||||
playedState: boolean
|
||||
) => {
|
||||
const { api, user } = currentApi;
|
||||
if (api && user?.Id) {
|
||||
if (playedState) {
|
||||
const response = await getPlaystateApi(api).markUnplayedItem({
|
||||
userId: user.Id,
|
||||
itemId: itemId
|
||||
});
|
||||
return response.data.Played;
|
||||
} else {
|
||||
const response = await getPlaystateApi(api).markPlayedItem({
|
||||
userId: user.Id,
|
||||
itemId: itemId
|
||||
});
|
||||
return response.data.Played;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const useTogglePlayedMutation = () => {
|
||||
const currentApi = useApi();
|
||||
return useMutation({
|
||||
mutationFn: ({ itemId, playedState }: TogglePlayedMutationProp) =>
|
||||
fetchUpdatePlayedState(currentApi, itemId, playedState )
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue