Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit 1036d0d

Browse files
author
Adam
committed
rewrite user list sidebar for responsiveness
1 parent f40948f commit 1036d0d

File tree

7 files changed

+161
-53
lines changed

7 files changed

+161
-53
lines changed

src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import { connect } from 'react-redux'
44
import { DragDropContext } from 'react-dnd'
55
import keydown from 'react-keydown/es'
66
import styled from 'styled-components'
7-
import { Divider } from 'react-md/lib/Dividers'
87

98
import { startTimer, stopTimer, setTime } from '@state/actions/timerActions'
109
import { TimerContainer } from './containers/Timer'
1110
import { UserContainer } from './containers/Users'
12-
import { GitHubLink } from './components/GitHubLink'
11+
// import { GitHubLink } from './components/GitHubLink'
1312
import { multiBackend } from './utils/dragDropContext'
1413
import { Time } from './time'
1514
import { IState } from './state'
@@ -70,11 +69,9 @@ export class AppComponent extends React.Component<
7069
<Container>
7170
<TimerContainer />
7271

73-
<Divider />
74-
7572
<UserContainer />
7673

77-
<GitHubLink />
74+
{/* <GitHubLink /> */}
7875
</Container>
7976
)
8077
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react'
2+
import styled from 'styled-components'
3+
4+
const ToHide = styled.span`
5+
@media only screen and (min-width: 600px) {
6+
display: none;
7+
}
8+
`
9+
10+
export const HideOnBigDevices: React.SFC = props => (
11+
<ToHide>{props.children}</ToHide>
12+
)

src/components/UserList.tsx

Lines changed: 88 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,68 @@
11
import * as React from 'react'
2-
import styled from 'styled-components'
2+
import styled, { StyledComponentClass } from 'styled-components'
33
import { List } from 'react-md/lib/Lists'
4+
import { Button, ButtonProps } from 'react-md/lib/Buttons'
45
import { Divider } from 'react-md/lib/Dividers'
5-
import { Button } from 'react-md/lib/Buttons'
66

77
import { DraggableUser } from './User'
88
import { AddUserDialog } from './AddUserDialog'
99

10-
const Container = styled.span`
10+
interface IContainerProps {
11+
hidden: boolean
12+
}
13+
14+
const Container = styled.div`
15+
position: fixed;
16+
right: 0;
17+
top: 0;
18+
bottom: 0;
1119
display: flex;
1220
flex-direction: column;
13-
justify-content: center;
21+
min-width: 175px;
22+
height: 100%;
1423
background: #fff;
15-
min-width: 170px;
24+
25+
@media only screen and (max-width: 600px) {
26+
left: 0;
27+
opacity: ${(p: IContainerProps) => (p.hidden ? 1 : 0)};
28+
pointer-events: ${(p: IContainerProps) => (p.hidden ? 'all' : 'none')};
29+
transition: opacity: 0.25s;
30+
}
31+
32+
@media only screen and (min-width: 1025px) {
33+
min-width: 225px;
34+
}
35+
`
36+
37+
const Wrapper = styled.div`
38+
display: flex;
39+
flex-direction: column;
40+
margin: auto 0;
41+
max-height: 100%;
42+
`
43+
44+
const ButtonWrapper = styled.div`
45+
display: flex;
46+
justify-content: space-around;
47+
`
48+
49+
const ButtonHideOnBigDevices: StyledComponentClass<ButtonProps, {}> = styled(
50+
Button
51+
)`
52+
@media only screen and (min-width: 600px) {
53+
display: none;
54+
}
1655
`
1756

1857
interface IProps {
1958
readonly users: ReadonlyArray<string>
2059
readonly activeUser: number
60+
readonly hideUserList: boolean
2161
readonly moveUser: (dragIndex: number, hoverIndex: number) => void
2262
readonly addUser: (name: string) => void
2363
readonly removeUser: (index: number) => void
2464
readonly setActive: (index: number) => void
65+
readonly toggleHideUserList: () => void
2566
}
2667

2768
interface IState {
@@ -43,33 +84,48 @@ export class UserList extends React.PureComponent<IProps, IState> {
4384

4485
public render() {
4586
return (
46-
<Container>
47-
<List>
48-
{this.props.users.map((user, i) => (
49-
<React.Fragment key={user}>
50-
{i !== 0 && <Divider />}
51-
52-
<DraggableUser
53-
user={user}
54-
active={this.props.activeUser === i}
55-
index={i}
56-
moveUser={this.props.moveUser}
57-
removeUser={this.props.removeUser}
58-
setActive={this.props.setActive}
59-
/>
60-
</React.Fragment>
61-
))}
62-
</List>
63-
64-
<Button
65-
raised
66-
primary
67-
iconChildren="add"
68-
style={{ margin: '5px 10px 0' }}
69-
onClick={this.showDialog}
70-
>
71-
Add User
72-
</Button>
87+
<Container hidden={this.props.hideUserList}>
88+
<Wrapper>
89+
<List style={{ overflowY: 'auto' }}>
90+
{this.props.users.map((user, i) => (
91+
<React.Fragment key={user}>
92+
{i !== 0 && <Divider />}
93+
94+
<DraggableUser
95+
user={user}
96+
active={this.props.activeUser === i}
97+
index={i}
98+
moveUser={this.props.moveUser}
99+
removeUser={this.props.removeUser}
100+
setActive={this.props.setActive}
101+
/>
102+
</React.Fragment>
103+
))}
104+
</List>
105+
106+
<Divider />
107+
108+
<ButtonWrapper>
109+
<Button
110+
raised
111+
primary
112+
iconChildren="add"
113+
style={{ margin: '15px', width: '100%' }}
114+
onClick={this.showDialog}
115+
>
116+
Add User
117+
</Button>
118+
119+
<ButtonHideOnBigDevices
120+
raised
121+
iconChildren="arrow_back"
122+
onClick={this.props.toggleHideUserList}
123+
style={{ margin: '15px', width: '100%' }}
124+
>
125+
Go back
126+
</ButtonHideOnBigDevices>
127+
</ButtonWrapper>
128+
</Wrapper>
73129

74130
<AddUserDialog
75131
visible={this.state.dialogVisible}

src/containers/Timer.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { IState as IRootState } from '@state/index'
1313
import { Time } from '../time'
1414
import { Countdown } from '../components/Countdown'
1515
import { KeyboardShortcutsDialog } from '../components/KeyboardShortcutsDialog'
16+
import { HideOnBigDevices } from '../components/HideOnBigDevices'
17+
import { toggleHideUserList } from '@state/actions/usersActions'
1618

1719
const Container = styled.div`
1820
display: flex;
@@ -39,6 +41,7 @@ interface IDispatchProps {
3941
startTimer: typeof startTimer
4042
stopTimer: typeof stopTimer
4143
countDownOneSecond: typeof countDownOneSecond
44+
toggleHideUserList: typeof toggleHideUserList
4245
}
4346

4447
const mapState = ({ timer }: IRootState): IStateProps => ({
@@ -47,7 +50,13 @@ const mapState = ({ timer }: IRootState): IStateProps => ({
4750
counting: timer.counting,
4851
})
4952

50-
const mapActions = { setTime, startTimer, stopTimer, countDownOneSecond }
53+
const mapActions: IDispatchProps = {
54+
setTime,
55+
startTimer,
56+
stopTimer,
57+
countDownOneSecond,
58+
toggleHideUserList,
59+
}
5160

5261
interface IState {
5362
dialogVisible: boolean
@@ -87,9 +96,17 @@ class TimerComponent extends React.PureComponent<
8796
onChangeTime={this.props.setTime}
8897
/>
8998

90-
<NonShrinkButton icon onClick={this.showDialog}>
91-
keyboard
92-
</NonShrinkButton>
99+
<div>
100+
<NonShrinkButton icon onClick={this.showDialog}>
101+
keyboard
102+
</NonShrinkButton>
103+
104+
<HideOnBigDevices>
105+
<NonShrinkButton icon onClick={this.props.toggleHideUserList}>
106+
people
107+
</NonShrinkButton>
108+
</HideOnBigDevices>
109+
</div>
93110

94111
<NonShrinkButton
95112
flat

src/containers/Users.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,37 @@ import {
77
addUser,
88
removeUser,
99
setActive,
10+
toggleHideUserList,
1011
} from '@state/actions/usersActions'
1112
import { UserList } from '../components/UserList'
1213

1314
interface IStateProps {
1415
readonly users: ReadonlyArray<string>
1516
readonly activeUser: number
17+
readonly hideUserList: boolean
1618
}
1719

1820
interface IActionProps {
1921
setOrder: typeof setOrder
2022
addUser: typeof addUser
2123
removeUser: typeof removeUser
2224
setActive: typeof setActive
25+
toggleHideUserList: typeof toggleHideUserList
2326
}
2427

2528
const mapState = ({ users }: IState): IStateProps => ({
2629
users: users.list,
2730
activeUser: users.activeUser,
31+
hideUserList: users.hideUserList,
2832
})
2933

30-
const mapActions = { setOrder, addUser, removeUser, setActive }
34+
const mapActions: IActionProps = {
35+
setOrder,
36+
addUser,
37+
removeUser,
38+
setActive,
39+
toggleHideUserList,
40+
}
3141

3242
class UserComponent extends React.PureComponent<IStateProps & IActionProps> {
3343
private moveUser = (dragIndex: number, hoverIndex: number) => {
@@ -40,16 +50,16 @@ class UserComponent extends React.PureComponent<IStateProps & IActionProps> {
4050

4151
public render() {
4252
return (
43-
<React.Fragment>
44-
<UserList
45-
users={this.props.users}
46-
activeUser={this.props.activeUser}
47-
moveUser={this.moveUser}
48-
addUser={this.props.addUser}
49-
removeUser={this.props.removeUser}
50-
setActive={this.props.setActive}
51-
/>
52-
</React.Fragment>
53+
<UserList
54+
users={this.props.users}
55+
activeUser={this.props.activeUser}
56+
hideUserList={this.props.hideUserList}
57+
moveUser={this.moveUser}
58+
addUser={this.props.addUser}
59+
removeUser={this.props.removeUser}
60+
setActive={this.props.setActive}
61+
toggleHideUserList={this.props.toggleHideUserList}
62+
/>
5363
)
5464
}
5565
}

src/state/actions/usersActions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const REMOVE_USER = 'REMOVE_USER'
44
export const SET_ORDER = 'SET_ORDER'
55
export const SET_ACTIVE = 'SET_ACTIVE'
66
export const SET_ACTIVE_NEXT = 'SET_ACTIVE_NEXT'
7+
export const TOGGLE_HIDE_USER_LIST = 'TOGGLE_HIDE_USER_LIST'
78

89
export type Actions = {
910
readonly ADD_USER: {
@@ -25,6 +26,9 @@ export type Actions = {
2526
readonly SET_ACTIVE_NEXT: {
2627
type: typeof SET_ACTIVE_NEXT
2728
}
29+
readonly TOGGLE_HIDE_USER_LIST: {
30+
type: typeof TOGGLE_HIDE_USER_LIST
31+
}
2832
}
2933

3034
export type RootAction = Actions[keyof Actions]
@@ -52,3 +56,7 @@ export const setActive = (payload: number): Actions[typeof SET_ACTIVE] => ({
5256
export const setActiveNext = (): Actions[typeof SET_ACTIVE_NEXT] => ({
5357
type: SET_ACTIVE_NEXT,
5458
})
59+
60+
export const toggleHideUserList = (): Actions[typeof TOGGLE_HIDE_USER_LIST] => ({
61+
type: TOGGLE_HIDE_USER_LIST,
62+
})

src/state/reducers/usersReducers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@ import {
66
REMOVE_USER,
77
ADD_USER,
88
SET_ACTIVE,
9+
TOGGLE_HIDE_USER_LIST,
910
} from '@state/actions/usersActions'
1011

1112
export type IStateUsers = {
1213
readonly list: ReadonlyArray<string>
1314
readonly activeUser: number
15+
readonly hideUserList: boolean
1416
}
1517

1618
const initialState: IStateUsers = {
1719
list: [],
1820
activeUser: 0,
21+
hideUserList: true,
1922
}
2023

2124
const cachedSettings = JSON.parse(
2225
localStorage.getItem('cache') || '{ "users": null }'
2326
).users
2427

2528
export const usersReducers = (
26-
state = Object.assign({}, initialState, cachedSettings),
29+
state: IStateUsers = Object.assign({}, initialState, cachedSettings),
2730
action: RootAction
2831
) => {
2932
switch (action.type) {
@@ -53,6 +56,11 @@ export const usersReducers = (
5356
activeUser: action.payload,
5457
})
5558

59+
case TOGGLE_HIDE_USER_LIST:
60+
return Object.assign({}, state, {
61+
hideUserList: !state.hideUserList,
62+
})
63+
5664
default:
5765
return state
5866
}

0 commit comments

Comments
 (0)