From d41c0f0ab76923b332ba51a75260c164cfc9f830 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 27 Mar 2024 15:13:49 +0200 Subject: [PATCH] Fixed: Movie search label on overflow views Fixed #9865 --- frontend/src/Movie/Index/MovieIndex.tsx | 2 + .../Movie/Index/MovieIndexSearchButton.tsx | 1 + .../Movie/Index/MovieIndexSearchMenuItem.tsx | 72 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 frontend/src/Movie/Index/MovieIndexSearchMenuItem.tsx diff --git a/frontend/src/Movie/Index/MovieIndex.tsx b/frontend/src/Movie/Index/MovieIndex.tsx index 629e3bf90..49eaf4eda 100644 --- a/frontend/src/Movie/Index/MovieIndex.tsx +++ b/frontend/src/Movie/Index/MovieIndex.tsx @@ -44,6 +44,7 @@ import MovieIndexViewMenu from './Menus/MovieIndexViewMenu'; import MovieIndexFooter from './MovieIndexFooter'; import MovieIndexRefreshMovieButton from './MovieIndexRefreshMovieButton'; import MovieIndexSearchButton from './MovieIndexSearchButton'; +import MovieIndexSearchMenuItem from './MovieIndexSearchMenuItem'; import MovieIndexOverviews from './Overview/MovieIndexOverviews'; import MovieIndexOverviewOptionsModal from './Overview/Options/MovieIndexOverviewOptionsModal'; import MovieIndexPosters from './Posters/MovieIndexPosters'; @@ -247,6 +248,7 @@ const MovieIndex = withScrollPosition((props: MovieIndexProps) => { ; } function MovieIndexSearchButton(props: MovieIndexSearchButtonProps) { diff --git a/frontend/src/Movie/Index/MovieIndexSearchMenuItem.tsx b/frontend/src/Movie/Index/MovieIndexSearchMenuItem.tsx new file mode 100644 index 000000000..2e80ba307 --- /dev/null +++ b/frontend/src/Movie/Index/MovieIndexSearchMenuItem.tsx @@ -0,0 +1,72 @@ +import React, { useCallback, useMemo } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { useSelect } from 'App/SelectContext'; +import ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState'; +import MoviesAppState, { MovieIndexAppState } from 'App/State/MoviesAppState'; +import { MOVIE_SEARCH } from 'Commands/commandNames'; +import PageToolbarOverflowMenuItem from 'Components/Page/Toolbar/PageToolbarOverflowMenuItem'; +import { icons } from 'Helpers/Props'; +import { executeCommand } from 'Store/Actions/commandActions'; +import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector'; +import createMovieClientSideCollectionItemsSelector from 'Store/Selectors/createMovieClientSideCollectionItemsSelector'; +import translate from 'Utilities/String/translate'; +import getSelectedIds from 'Utilities/Table/getSelectedIds'; + +interface MovieIndexSearchMenuItemProps { + isSelectMode: boolean; + selectedFilterKey: string; +} + +function MovieIndexSearchMenuItem(props: MovieIndexSearchMenuItemProps) { + const isSearching = useSelector(createCommandExecutingSelector(MOVIE_SEARCH)); + const { + items, + }: MoviesAppState & MovieIndexAppState & ClientSideCollectionAppState = + useSelector(createMovieClientSideCollectionItemsSelector('movieIndex')); + + const dispatch = useDispatch(); + + const { isSelectMode, selectedFilterKey } = props; + const [selectState] = useSelect(); + const { selectedState } = selectState; + + const selectedMovieIds = useMemo(() => { + return getSelectedIds(selectedState); + }, [selectedState]); + + const moviesToSearch = + isSelectMode && selectedMovieIds.length > 0 + ? selectedMovieIds + : items.map((m) => m.id); + + const searchIndexLabel = + selectedFilterKey === 'all' + ? translate('SearchAll') + : translate('SearchFiltered'); + + const searchSelectLabel = + selectedMovieIds.length > 0 + ? translate('SearchSelected') + : translate('SearchAll'); + + const onPress = useCallback(() => { + dispatch( + executeCommand({ + name: MOVIE_SEARCH, + movieIds: moviesToSearch, + }) + ); + }, [dispatch, moviesToSearch]); + + return ( + + ); +} + +export default MovieIndexSearchMenuItem;