Skip to content

Commit

Permalink
#79 updated navigation by tabIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
artzub committed Jan 8, 2021
1 parent 729089e commit 586b90a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/components/Header/components/BranchStep/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { useDebounce } from 'react-use';
import { FixedSizeList } from 'react-window';
import styled from 'styled-components';
import ListItemButton from '../shared/ListItemButton';
import Marker from '../shared/Marker';
import Secondary from './Secondary';

Expand Down Expand Up @@ -115,11 +116,13 @@ const Body = () => {

return (
<ListItem
component={ListItemButton}
alignItems="center"
key={item.name}
onClick={onClick(item)}
style={style}
title={item.name}
tabIndex="0"
>
<ListItemAvatar>
<Avatar>
Expand Down
62 changes: 27 additions & 35 deletions src/components/Header/components/ProfileStep/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import LoadingOverlay from '@/shared/components/LoadingOverlay';
import ScrollBar from '@/shared/components/ScrollBar';
import { useUIProperty } from '@/shared/hooks';
import { useRedirectTo } from '@/shared/hooks/useRedirectTo';
import {
Avatar, ListItem as ListItemOrigin,
ListItemAvatar, ListSubheader,
TextField,
} from '@material-ui/core';
import { Avatar, ListItem as ListItemOrigin, ListItemAvatar, ListSubheader, TextField } from '@material-ui/core';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import { useDispatch, useSelector } from 'react-redux';
import { useDebounce } from 'react-use';
import styled from 'styled-components';
import ListItemButton from '../shared/ListItemButton';

const Container = styled.div`
min-height: 100px;
Expand Down Expand Up @@ -115,6 +112,27 @@ const Body = () => {
[bodyOpen],
);

const Item = useCallback(
(profile) => (
<ListItem
component={ListItemButton}
alignItems="center"
key={profile.login}
onClick={onClick(profile)}
tabIndex="0"
>
<ListItemAvatar>
<Avatar src={profile.avatar} />
</ListItemAvatar>
<ListItemText
primary={<Highlight search={search} text={profile.login} />}
secondary={profile.type}
/>
</ListItem>
),
[search, onClick],
);

return (
<Container>
<TextField
Expand All @@ -127,48 +145,22 @@ const Body = () => {
<ListContainer>
{!neverChange && (
<List
component="div"
ref={listRef}
dense
subheader={SearchHeader}
>
{!items.length && <NotData />}
{(items || []).map((profile) => (
<ListItem
alignItems="center"
key={profile.login}
onClick={onClick(profile)}
>
<ListItemAvatar>
<Avatar src={profile.avatar} />
</ListItemAvatar>
<ListItemText
primary={<Highlight search={search} text={profile.login} />}
secondary={profile.type}
/>
</ListItem>
))}
{(items || []).map(Item)}
</List>
)}
{!!top.length && (
<List
component="div"
dense
subheader={TopHeader}
>
{(top || []).map((profile) => (
<ListItem
alignItems="center"
key={profile.login}
onClick={onClick(profile)}
>
<ListItemAvatar>
<Avatar src={profile.avatar} />
</ListItemAvatar>
<ListItemText
primary={profile.login}
secondary={profile.type}
/>
</ListItem>
))}
{(top || []).map(Item)}
</List>
)}
</ListContainer>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Header/components/RepositoryStep/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { useDebounce } from 'react-use';
import { FixedSizeList } from 'react-window';
import styled from 'styled-components';
import ListItemButton from '../shared/ListItemButton';
import Marker from '../shared/Marker';
import Secondary from './Secondary';

Expand Down Expand Up @@ -117,11 +118,13 @@ const Body = () => {

return (
<ListItem
component={ListItemButton}
alignItems="center"
key={item.name}
onClick={onClick(item)}
style={style}
title={`${title} | ${item.name}`}
tabIndex="0"
>
<ListItemAvatar>
<Avatar>
Expand Down Expand Up @@ -174,6 +177,7 @@ const Body = () => {
<LoadingOverlay loading={isFetching}>
{/*<ListContainer>*/}
<List
component="div"
dense
subheader={ListHeader}
>
Expand Down
26 changes: 22 additions & 4 deletions src/components/Header/components/ShowStep/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IconButton } from '@material-ui/core';
import PauseIcon from 'mdi-react/PauseIcon';
import PlayArrowIcon from 'mdi-react/PlayArrowIcon';
import ReplayIcon from 'mdi-react/ReplayIcon';
import PropTypes from 'prop-types';
import { useEvent } from 'react-use';
import styled from 'styled-components';
import HeaderContainer from '../shared/HeaderContainer';
Expand All @@ -29,6 +30,7 @@ const ButtonContainer = styled.div`


const Header = (props) => {
const { disabled, ...rest } = props;
const [start, setStart] = useUIProperty('start');
const [pause, setPause] = useUIProperty('pause');

Expand Down Expand Up @@ -59,17 +61,25 @@ const Header = (props) => {

return (
<HeaderContainer
{...props}
tabIndex={-1}
{...rest}
tabIndex="-1"
button={false}
>
<ButtonContainer>
<IconButton size="small" onClick={onClick(isRun ? 'pause' : 'start')}>
<IconButton
size="small"
onClick={onClick(isRun ? 'pause' : 'start')}
disabled={disabled}
>
{isRun && <PauseIcon size={24} />}
{!isRun && <PlayArrowIcon size={24} />}
</IconButton>
{start && pause && (
<IconButton size="small" onClick={onClick('replay')}>
<IconButton
size="small"
onClick={onClick('replay')}
disabled={disabled}
>
<ReplayIcon size={24} />
</IconButton>
)}
Expand All @@ -78,4 +88,12 @@ const Header = (props) => {
);
};

Header.propTypes = {
disabled: PropTypes.bool,
};

Header.defaultProps = {
disabled: false,
};

export default Header;
11 changes: 11 additions & 0 deletions src/components/Header/components/shared/ListItemButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styled from 'styled-components';

const ListItemButton = styled.button.attrs({
type: 'button',
})`
background: transparent;
border: 0;
color: inherit;
`;

export default ListItemButton;
4 changes: 2 additions & 2 deletions src/components/StageController/useStageProfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export const useStageProfiles = (service, profile) => {
return;
}

dispatch(profilesSlice.actions.fetchProfile(profile));
dispatch(profilesSlice.actions.fetchProfile(profile, 'profile'));

return () => {
dispatch(profilesSlice.actions.cancel());
dispatch(profilesSlice.actions.cancel('profile'));
};
},
[profile, login, dispatch],
Expand Down

0 comments on commit 586b90a

Please sign in to comment.