All files / components/settings/DataSourceToggle DataSourceToggle.tsx

0% Statements 0/7
0% Branches 0/4
0% Functions 0/2
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                                                                               
import { IconButton } from '@mui/material';
import { Storage, CloudQueue } from '@mui/icons-material';
import { useTheme } from '@mui/material/styles';
import { useSelector, useDispatch } from 'react-redux';
import { selectDataSource } from '@/store/reducers/settings/settings-selectors';
import { setDataSource } from '@/store/reducers/settings/settings-actions';
import { DataSource } from '@/enums/settings';
 
function DataSourceToggle() {
  const dataSource = useSelector(selectDataSource);
  const theme = useTheme();
  const dispatch = useDispatch();
 
  const handleToggle = () => {
    const newDataSource = dataSource === DataSource.ReduxSaga ? DataSource.TanStack : DataSource.ReduxSaga;
    dispatch(setDataSource(newDataSource));
  };
 
  return (
    <IconButton
      onClick={handleToggle}
      aria-label="toggle data source"
      data-testid="data-source-toggle-button"
      sx={{
        color: theme.palette.navigation.text,
        backgroundColor: 'transparent',
        '&:hover': {
          backgroundColor: theme.palette.navigation.hover,
          color: theme.palette.navigation.active,
        },
        transition: 'all 0.3s ease',
      }}
    >
      {dataSource === DataSource.ReduxSaga ? <Storage /> : <CloudQueue />}
    </IconButton>
  );
}
 
export default DataSourceToggle;