1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

apply suggestion

This commit is contained in:
grafixeyehero 2024-01-12 02:21:41 +03:00
parent 78b680f614
commit 3d15b85d10
3 changed files with 41 additions and 43 deletions

View file

@ -8,32 +8,30 @@ import { useTogglePlayedMutation } from 'hooks/useFetchItems';
interface PlayedButtonProps {
className?: string;
playedState : boolean | undefined;
isPlayed : boolean | undefined;
itemId: string | null | undefined;
itemType: string | null | undefined
}
const PlayedButton: FC<PlayedButtonProps> = ({
className,
playedState = false,
isPlayed = false,
itemId,
itemType
}) => {
const { mutateAsync: togglePlayedMutation } = useTogglePlayedMutation();
const [isPlayed, setIsPlayed] = React.useState<boolean | undefined>(
playedState ?? false
);
const [playedState, setPlayedState] = React.useState<boolean>(isPlayed);
const getTitle = useCallback(() => {
let buttonTitle;
if (itemType !== BaseItemKind.AudioBook) {
buttonTitle = isPlayed ? globalize.translate('Watched') : globalize.translate('MarkPlayed');
buttonTitle = playedState ? globalize.translate('Watched') : globalize.translate('MarkPlayed');
} else {
buttonTitle = isPlayed ? globalize.translate('Played') : globalize.translate('MarkPlayed');
buttonTitle = playedState ? globalize.translate('Played') : globalize.translate('MarkPlayed');
}
return buttonTitle;
}, [isPlayed, itemType]);
}, [playedState, itemType]);
const onClick = useCallback(async () => {
try {
@ -41,23 +39,23 @@ const PlayedButton: FC<PlayedButtonProps> = ({
throw new Error('Item has no Id');
}
const response = await togglePlayedMutation({
const _isPlayed = await togglePlayedMutation({
itemId,
isPlayed
playedState
});
setIsPlayed(response?.Played);
setPlayedState(!!_isPlayed);
} catch (e) {
console.error(e);
}
}, [isPlayed, itemId, togglePlayedMutation]);
}, [playedState, itemId, togglePlayedMutation]);
const btnClass = classNames(
className,
{ 'playstatebutton-played': isPlayed }
{ 'playstatebutton-played': playedState }
);
const iconClass = classNames(
{ 'playstatebutton-icon-played': isPlayed }
{ 'playstatebutton-icon-played': playedState }
);
return (
<IconButton

View file

@ -7,17 +7,17 @@ import globalize from 'scripts/globalize';
interface FavoriteButtonProps {
className?: string;
favoriteState: boolean | undefined;
isFavorite: boolean | undefined;
itemId: string | null | undefined
}
const FavoriteButton: FC<FavoriteButtonProps> = ({
className,
favoriteState,
isFavorite = false,
itemId
}) => {
const { mutateAsync: toggleFavoriteMutation } = useToggleFavoriteMutation();
const [isFavorite, setIsFavorite] = React.useState<boolean | undefined>(favoriteState ?? false);
const [favoriteState, setFavoriteState] = React.useState<boolean>(isFavorite);
const onClick = useCallback(async () => {
try {
@ -25,28 +25,28 @@ const FavoriteButton: FC<FavoriteButtonProps> = ({
throw new Error('Item has no Id');
}
const response = await toggleFavoriteMutation({
const _isFavorite = await toggleFavoriteMutation({
itemId,
isFavorite
favoriteState
});
setIsFavorite(response?.IsFavorite);
setFavoriteState(!!_isFavorite);
} catch (e) {
console.error(e);
}
}, [isFavorite, itemId, toggleFavoriteMutation]);
}, [favoriteState, itemId, toggleFavoriteMutation]);
const btnClass = classNames(
className,
{ 'ratingbutton-withrating': isFavorite }
{ 'ratingbutton-withrating': favoriteState }
);
const iconClass = classNames(
{ 'ratingbutton-icon-withrating': isFavorite }
{ 'ratingbutton-icon-withrating': favoriteState }
);
return (
<IconButton
title={isFavorite ? globalize.translate('Favorite') : globalize.translate('AddToFavorites')}
title={favoriteState ? globalize.translate('Favorite') : globalize.translate('AddToFavorites')}
className={btnClass}
size='small'
onClick={onClick}