Remove redundant code in selecting with click on poster

(cherry picked from commit b116f63a1d95a23a6f3684e6b60ead60c2584f0f)
This commit is contained in:
Bogdan 2025-08-17 13:24:22 +03:00 committed by bakerboy448
parent 1e72cc6b5a
commit abf3fc4557
4 changed files with 24 additions and 34 deletions

View file

@ -67,6 +67,7 @@ function MovieIndexOverview(props: MovieIndexOverviewProps) {
monitored, monitored,
status, status,
path, path,
titleSlug,
overview, overview,
statistics = {} as Statistics, statistics = {} as Statistics,
images, images,
@ -141,7 +142,9 @@ function MovieIndexOverview(props: MovieIndexOverviewProps) {
<div className={styles.content}> <div className={styles.content}>
<div className={styles.poster}> <div className={styles.poster}>
<div className={styles.posterContainer}> <div className={styles.posterContainer}>
{isSelectMode ? <MovieIndexPosterSelect movieId={movieId} /> : null} {isSelectMode ? (
<MovieIndexPosterSelect movieId={movieId} titleSlug={titleSlug} />
) : null}
{status === 'deleted' ? ( {status === 'deleted' ? (
<div className={styles.deleted} title={translate('Deleted')} /> <div className={styles.deleted} title={translate('Deleted')} />

View file

@ -1,6 +1,5 @@
import React, { SyntheticEvent, useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useSelect } from 'App/SelectContext';
import { MOVIE_SEARCH, REFRESH_MOVIE } from 'Commands/commandNames'; import { MOVIE_SEARCH, REFRESH_MOVIE } from 'Commands/commandNames';
import Icon from 'Components/Icon'; import Icon from 'Components/Icon';
import ImdbRating from 'Components/ImdbRating'; import ImdbRating from 'Components/ImdbRating';
@ -70,6 +69,7 @@ function MovieIndexPoster(props: MovieIndexPosterProps) {
monitored, monitored,
status, status,
images, images,
titleSlug,
tmdbId, tmdbId,
imdbId, imdbId,
youTubeTrailerId, youTubeTrailerId,
@ -142,30 +142,7 @@ function MovieIndexPoster(props: MovieIndexPosterProps) {
setIsDeleteMovieModalOpen(false); setIsDeleteMovieModalOpen(false);
}, [setIsDeleteMovieModalOpen]); }, [setIsDeleteMovieModalOpen]);
const [selectState, selectDispatch] = useSelect(); const link = `/movie/${titleSlug}`;
const onSelectPress = useCallback(
(event: SyntheticEvent<HTMLElement, MouseEvent>) => {
if (event.nativeEvent.ctrlKey || event.nativeEvent.metaKey) {
window.open(`/movie/${tmdbId}`, '_blank');
return;
}
const shiftKey = event.nativeEvent.shiftKey;
selectDispatch({
type: 'toggleSelected',
id: movieId,
isSelected: !selectState.selectedState[movieId],
shiftKey,
});
},
[movieId, selectState.selectedState, selectDispatch, tmdbId]
);
const link = `/movie/${tmdbId}`;
const linkProps = isSelectMode ? { onPress: onSelectPress } : { to: link };
const elementStyle = { const elementStyle = {
width: `${posterWidth}px`, width: `${posterWidth}px`,
@ -175,7 +152,9 @@ function MovieIndexPoster(props: MovieIndexPosterProps) {
return ( return (
<div className={styles.content}> <div className={styles.content}>
<div className={styles.posterContainer} title={title}> <div className={styles.posterContainer} title={title}>
{isSelectMode ? <MovieIndexPosterSelect movieId={movieId} /> : null} {isSelectMode ? (
<MovieIndexPosterSelect movieId={movieId} titleSlug={titleSlug} />
) : null}
<Label className={styles.controls}> <Label className={styles.controls}>
<SpinnerIconButton <SpinnerIconButton
@ -220,7 +199,7 @@ function MovieIndexPoster(props: MovieIndexPosterProps) {
<div className={styles.deleted} title={translate('Deleted')} /> <div className={styles.deleted} title={translate('Deleted')} />
) : null} ) : null}
<Link className={styles.link} style={elementStyle} {...linkProps}> <Link className={styles.link} style={elementStyle} to={link}>
<MoviePoster <MoviePoster
style={elementStyle} style={elementStyle}
images={images} images={images}

View file

@ -3,8 +3,8 @@
top: 0; top: 0;
left: 0; left: 0;
z-index: 3; z-index: 3;
width: 36px; width: 100%;
height: 36px; height: 100%;
} }
.checkContainer { .checkContainer {

View file

@ -7,15 +7,23 @@ import styles from './MovieIndexPosterSelect.css';
interface MovieIndexPosterSelectProps { interface MovieIndexPosterSelectProps {
movieId: number; movieId: number;
titleSlug: string;
} }
function MovieIndexPosterSelect(props: MovieIndexPosterSelectProps) { function MovieIndexPosterSelect({
const { movieId } = props; movieId,
titleSlug,
}: MovieIndexPosterSelectProps) {
const [selectState, selectDispatch] = useSelect(); const [selectState, selectDispatch] = useSelect();
const isSelected = selectState.selectedState[movieId]; const isSelected = selectState.selectedState[movieId];
const onSelectPress = useCallback( const onSelectPress = useCallback(
(event: SyntheticEvent<HTMLElement, PointerEvent>) => { (event: SyntheticEvent<HTMLElement, PointerEvent>) => {
if (event.nativeEvent.ctrlKey || event.nativeEvent.metaKey) {
window.open(`${window.Radarr.urlBase}/movie/${titleSlug}`, '_blank');
return;
}
const shiftKey = event.nativeEvent.shiftKey; const shiftKey = event.nativeEvent.shiftKey;
selectDispatch({ selectDispatch({
@ -25,7 +33,7 @@ function MovieIndexPosterSelect(props: MovieIndexPosterSelectProps) {
shiftKey, shiftKey,
}); });
}, },
[movieId, isSelected, selectDispatch] [movieId, titleSlug, isSelected, selectDispatch]
); );
return ( return (