Skip to content

Commit

Permalink
Refactor UploadSettings to use useAppSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Apr 23, 2024
1 parent e11b9e6 commit 035e5ce
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/usecase/settings/UploadSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,26 @@ import {
View
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { ConnectedProps, connect } from 'react-redux';
import { StoreState } from '../../store';
import { setMediaUploadOptionsAction } from '../../store/actions';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import UndoTextInput from '../shared/UndoTextInput';
import { styles } from './styles';
import { setMediaUploadOptionsAction } from '../../store/actions';

const connector = connect((state: StoreState) => ({
uploadOptions: {
...state.connection.mediaUploadOptions,
headers:
state.connection.mediaUploadOptions.headers &&
Object.entries(state.connection.mediaUploadOptions.headers)
}
}));

type Props = {
setShowUploadSettings: (show: boolean) => void;
} & ConnectedProps<typeof connector>;

const UploadSettings: React.FC<Props> = ({
uploadOptions: {
headers: uploadOptionsHeaders = [['', '']],
...uploadOptions
},
dispatch,
setShowUploadSettings
}) => {
};

const UploadSettings: React.FC<Props> = ({ setShowUploadSettings }) => {
const dispatch = useAppDispatch();

const uploadOptions = useAppSelector(
(state) => state.connection.mediaUploadOptions
);

const uploadOptionsHeaders = uploadOptions.headers
? Object.entries(uploadOptions.headers)
: [['', '']];

const [uploadOptionsState, setUploadOptionsState] = useState({
...uploadOptions,
headers: uploadOptionsHeaders
Expand Down Expand Up @@ -233,4 +226,4 @@ const UploadSettings: React.FC<Props> = ({
);
};

export default connector(UploadSettings);
export default UploadSettings;

0 comments on commit 035e5ce

Please sign in to comment.