2023-04-13 23:56:55 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2023-05-01 01:37:45 +00:00
|
|
|
import { useSelect } from 'App/SelectContext';
|
2023-04-13 23:56:55 +00:00
|
|
|
import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton';
|
|
|
|
import { icons } from 'Helpers/Props';
|
|
|
|
|
2023-04-22 18:52:31 +00:00
|
|
|
interface MovieIndexSelectAllButtonProps {
|
|
|
|
label: string;
|
|
|
|
isSelectMode: boolean;
|
2023-05-03 04:07:12 +00:00
|
|
|
overflowComponent: React.FunctionComponent<never>;
|
2023-04-22 18:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function MovieIndexSelectAllButton(props: MovieIndexSelectAllButtonProps) {
|
|
|
|
const { isSelectMode } = props;
|
2023-04-13 23:56:55 +00:00
|
|
|
const [selectState, selectDispatch] = useSelect();
|
|
|
|
const { allSelected, allUnselected } = selectState;
|
|
|
|
|
|
|
|
let icon = icons.SQUARE_MINUS;
|
|
|
|
|
|
|
|
if (allSelected) {
|
|
|
|
icon = icons.CHECK_SQUARE;
|
|
|
|
} else if (allUnselected) {
|
|
|
|
icon = icons.SQUARE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onPress = useCallback(() => {
|
|
|
|
selectDispatch({
|
2023-05-01 01:37:45 +00:00
|
|
|
type: allSelected ? 'unselectAll' : 'selectAll',
|
2023-04-13 23:56:55 +00:00
|
|
|
});
|
|
|
|
}, [allSelected, selectDispatch]);
|
|
|
|
|
2023-04-22 18:52:31 +00:00
|
|
|
return isSelectMode ? (
|
2023-04-13 23:56:55 +00:00
|
|
|
<PageToolbarButton
|
|
|
|
label={allSelected ? 'Unselect All' : 'Select All'}
|
|
|
|
iconName={icon}
|
|
|
|
onPress={onPress}
|
|
|
|
/>
|
2023-04-22 18:52:31 +00:00
|
|
|
) : null;
|
2023-04-13 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default MovieIndexSelectAllButton;
|