Simplify defaults set when adding release profiles and list exclusions

pull/10519/head
Bogdan 3 months ago
parent 63a7d33e7e
commit cfdb7a15de

@ -19,7 +19,7 @@ function EditImportListExclusionModal(
const dispatch = useDispatch(); const dispatch = useDispatch();
const onModalClosePress = useCallback(() => { const handleModalClose = useCallback(() => {
dispatch( dispatch(
clearPendingChanges({ clearPendingChanges({
section: 'settings.importListExclusions', section: 'settings.importListExclusions',
@ -29,10 +29,10 @@ function EditImportListExclusionModal(
}, [dispatch, onModalClose]); }, [dispatch, onModalClose]);
return ( return (
<Modal size={sizes.MEDIUM} isOpen={isOpen} onModalClose={onModalClosePress}> <Modal size={sizes.MEDIUM} isOpen={isOpen} onModalClose={handleModalClose}>
<EditImportListExclusionModalContent <EditImportListExclusionModalContent
{...otherProps} {...otherProps}
onModalClose={onModalClosePress} onModalClose={handleModalClose}
/> />
</Modal> </Modal>
); );

@ -32,12 +32,6 @@ const newImportListExclusion = {
tmdbId: 0, tmdbId: 0,
}; };
interface EditImportListExclusionModalContentProps {
id?: number;
onModalClose: () => void;
onDeleteImportListExclusionPress?: () => void;
}
function createImportListExclusionSelector(id?: number) { function createImportListExclusionSelector(id?: number) {
return createSelector( return createSelector(
(state: AppState) => state.settings.importListExclusions, (state: AppState) => state.settings.importListExclusions,
@ -63,12 +57,24 @@ function createImportListExclusionSelector(id?: number) {
); );
} }
function EditImportListExclusionModalContent( interface EditImportListExclusionModalContentProps {
props: EditImportListExclusionModalContentProps id?: number;
) { onModalClose: () => void;
const { id, onModalClose, onDeleteImportListExclusionPress } = props; onDeleteImportListExclusionPress?: () => void;
}
function EditImportListExclusionModalContent({
id,
onModalClose,
onDeleteImportListExclusionPress,
}: EditImportListExclusionModalContentProps) {
const { isFetching, isSaving, item, error, saveError, ...otherProps } =
useSelector(createImportListExclusionSelector(id));
const { movieTitle, movieYear, tmdbId } = item;
const dispatch = useDispatch(); const dispatch = useDispatch();
const previousIsSaving = usePrevious(isSaving);
const dispatchSetImportListExclusionValue = (payload: { const dispatchSetImportListExclusionValue = (payload: {
name: string; name: string;
@ -78,20 +84,10 @@ function EditImportListExclusionModalContent(
dispatch(setImportListExclusionValue(payload)); dispatch(setImportListExclusionValue(payload));
}; };
const { isFetching, isSaving, item, error, saveError, ...otherProps } =
useSelector(createImportListExclusionSelector(props.id));
const previousIsSaving = usePrevious(isSaving);
const { movieTitle, movieYear, tmdbId } = item;
useEffect(() => { useEffect(() => {
if (!id) { if (!id) {
Object.keys(newImportListExclusion).forEach((name) => { Object.entries(newImportListExclusion).forEach(([name, value]) => {
dispatchSetImportListExclusionValue({ dispatchSetImportListExclusionValue({ name, value });
name,
value:
newImportListExclusion[name as keyof typeof newImportListExclusion],
});
}); });
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -101,7 +97,7 @@ function EditImportListExclusionModalContent(
if (previousIsSaving && !isSaving && !saveError) { if (previousIsSaving && !isSaving && !saveError) {
onModalClose(); onModalClose();
} }
}); }, [previousIsSaving, isSaving, saveError, onModalClose]);
const onSavePress = useCallback(() => { const onSavePress = useCallback(() => {
dispatch(saveImportListExclusion({ id })); dispatch(saveImportListExclusion({ id }));

@ -19,7 +19,7 @@ function EditReleaseProfileModal({
}: EditReleaseProfileModalProps) { }: EditReleaseProfileModalProps) {
const dispatch = useDispatch(); const dispatch = useDispatch();
const onModalClosePress = useCallback(() => { const handleModalClose = useCallback(() => {
dispatch( dispatch(
clearPendingChanges({ clearPendingChanges({
section: 'settings.releaseProfiles', section: 'settings.releaseProfiles',
@ -29,10 +29,10 @@ function EditReleaseProfileModal({
}, [dispatch, onModalClose]); }, [dispatch, onModalClose]);
return ( return (
<Modal size={sizes.MEDIUM} isOpen={isOpen} onModalClose={onModalClosePress}> <Modal size={sizes.MEDIUM} isOpen={isOpen} onModalClose={handleModalClose}>
<EditReleaseProfileModalContent <EditReleaseProfileModalContent
{...otherProps} {...otherProps}
onModalClose={onModalClosePress} onModalClose={handleModalClose}
/> />
</Modal> </Modal>
); );

@ -63,11 +63,11 @@ interface EditReleaseProfileModalContentProps {
onDeleteReleaseProfilePress?: () => void; onDeleteReleaseProfilePress?: () => void;
} }
function EditReleaseProfileModalContent( function EditReleaseProfileModalContent({
props: EditReleaseProfileModalContentProps id,
) { onModalClose,
const { id, onModalClose, onDeleteReleaseProfilePress } = props; onDeleteReleaseProfilePress,
}: EditReleaseProfileModalContentProps) {
const { item, isFetching, isSaving, error, saveError, ...otherProps } = const { item, isFetching, isSaving, error, saveError, ...otherProps } =
useSelector(createReleaseProfileSelector(id)); useSelector(createReleaseProfileSelector(id));
@ -78,14 +78,9 @@ function EditReleaseProfileModalContent(
useEffect(() => { useEffect(() => {
if (!id) { if (!id) {
Object.keys(newReleaseProfile).forEach((name) => { Object.entries(newReleaseProfile).forEach(([name, value]) => {
dispatch(
// @ts-expect-error 'setReleaseProfileValue' isn't typed yet // @ts-expect-error 'setReleaseProfileValue' isn't typed yet
setReleaseProfileValue({ dispatch(setReleaseProfileValue({ name, value }));
name,
value: newReleaseProfile[name as keyof typeof newReleaseProfile],
})
);
}); });
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -95,7 +90,7 @@ function EditReleaseProfileModalContent(
if (previousIsSaving && !isSaving && !saveError) { if (previousIsSaving && !isSaving && !saveError) {
onModalClose(); onModalClose();
} }
}); }, [previousIsSaving, isSaving, saveError, onModalClose]);
const handleSavePress = useCallback(() => { const handleSavePress = useCallback(() => {
dispatch(saveReleaseProfile({ id })); dispatch(saveReleaseProfile({ id }));

Loading…
Cancel
Save