@@ -21,36 +21,57 @@ import React from 'react';
21
21
22
22
import { connect } from 'react-redux' ;
23
23
24
- import AccountIcon from './AccountIcon' ;
25
- import AddAccountTrigger from './context/AddAccountTrigger' ;
26
- import EditAccountMenu from './context/EditAccountMenu' ;
27
24
import './Sidebar.css' ;
28
25
29
- import { EVENT_TYPE } from '../../../dist/lib/eventType' ;
30
- import { addAccountWithSession , setAccountContextHidden , toggleEditAccountMenuVisibility } from '../actions' ;
31
- import { colorFromId } from '../lib/accentColor' ;
32
- import { isEnterKey } from '../lib/keyboardUtil' ;
33
- import { preventFocus } from '../lib/util' ;
34
- import { AccountSelector } from '../selector/AccountSelector' ;
35
- import { ContextMenuSelector } from '../selector/ContextMenuSelector' ;
26
+ import { EVENT_TYPE } from '../../../../src/lib/eventType' ;
27
+ import { addAccountWithSession , setAccountContextHidden , toggleEditAccountMenuVisibility } from '../../actions' ;
28
+ import { colorFromId } from '../../lib/accentColor' ;
29
+ import { isEnterKey } from '../../lib/keyboardUtil' ;
30
+ import { preventFocus } from '../../lib/util' ;
31
+ import { AccountSelector } from '../../selector/AccountSelector' ;
32
+ import { ContextMenuSelector } from '../../selector/ContextMenuSelector' ;
33
+ import { Account } from '../../types/account' ;
34
+ import { AccountIcon } from '../AccountIcon' ;
35
+ import AddAccountTrigger from '../context/AddAccountTrigger' ;
36
+ import EditAccountMenu from '../context/EditAccountMenu' ;
36
37
37
- const centerOfEventTarget = event => {
38
+ const centerOfEventTarget = ( event : React . MouseEvent < Element , MouseEvent > ) => {
38
39
const clientRectangle = event . currentTarget . getBoundingClientRect ( ) ;
39
40
const centerX = clientRectangle . left + clientRectangle . width / 2 ;
40
41
const centerY = clientRectangle . top + clientRectangle . height / 2 ;
41
42
return { centerX, centerY} ;
42
43
} ;
43
44
44
- const getClassName = account => {
45
+ const getClassName = ( account : Account ) => {
45
46
const showIconBadge = account . badgeCount > 0 ? ' Sidebar-icon-badge' : '' ;
46
47
const showIconCursor = account . visible ? '' : ' Sidebar-icon-cursor' ;
47
48
return `Sidebar-icon${ showIconBadge } ${ showIconCursor } ` ;
48
49
} ;
49
50
50
- const handleSwitchAccount = accountIndex => {
51
+ const handleSwitchAccount = ( accountIndex : number ) => {
51
52
window . dispatchEvent ( new CustomEvent ( EVENT_TYPE . ACTION . SWITCH_ACCOUNT , { detail : { accountIndex : accountIndex } } ) ) ;
52
53
} ;
53
54
55
+ interface SidebarProps {
56
+ accounts : Account [ ] ;
57
+ currentAccentID : number ;
58
+ hasCreatedAccount : boolean ;
59
+ hasReachedLimitOfAccounts : boolean ;
60
+ isAddingAccount : boolean ;
61
+ isDarkMode : boolean ;
62
+ isEditAccountMenuVisible : boolean ;
63
+ setAccountContextHidden : ( ) => void ;
64
+ toggleEditAccountMenuVisibility : (
65
+ centerX : number ,
66
+ centerY : number ,
67
+ accountId : string ,
68
+ sessionID : string ,
69
+ lifecycle : string ,
70
+ isAtLeastAdmin : boolean ,
71
+ ) => void ;
72
+ addAccountWithSession : ( ) => void ;
73
+ }
74
+
54
75
const Sidebar = ( {
55
76
accounts,
56
77
currentAccentID,
@@ -60,18 +81,22 @@ const Sidebar = ({
60
81
isAddingAccount,
61
82
isEditAccountMenuVisible,
62
83
...connected
63
- } ) => (
84
+ } : SidebarProps ) => (
64
85
< div
86
+ role = "button"
87
+ tabIndex = { 0 }
65
88
className = { `${ isDarkMode ? 'Sidebar theme-dark' : 'Sidebar theme-light' } ` }
66
89
style = { ! hasCreatedAccount ? { display : 'none' } : { } }
67
90
onMouseDown = { preventFocus ( ) }
91
+ onKeyDown = { connected . setAccountContextHidden }
68
92
onClick = { connected . setAccountContextHidden }
69
93
>
70
94
{ accounts . map ( account => {
71
95
const accountIndex = accounts . indexOf ( account ) ;
72
96
return (
73
97
< div className = "Sidebar-cell" key = { account . id } >
74
98
< div
99
+ role = "button"
75
100
style = { { color : colorFromId ( currentAccentID ) } }
76
101
className = { getClassName ( account ) }
77
102
tabIndex = { 0 }
@@ -81,7 +106,7 @@ const Sidebar = ({
81
106
handleSwitchAccount ( accountIndex ) ;
82
107
}
83
108
} }
84
- onContextMenu = { preventFocus ( event => {
109
+ onContextMenu = { preventFocus ( ( event : React . MouseEvent < Element , MouseEvent > ) => {
85
110
const isAtLeastAdmin =
86
111
account . teamRole === 'z.team.TeamRole.ROLE.OWNER' || account . teamRole === 'z.team.TeamRole.ROLE.ADMIN' ;
87
112
const { centerX, centerY} = centerOfEventTarget ( event ) ;
@@ -101,6 +126,7 @@ const Sidebar = ({
101
126
</ div >
102
127
) ;
103
128
} ) }
129
+
104
130
{ ! isAddingAccount && ! hasReachedLimitOfAccounts && (
105
131
< AddAccountTrigger id = "account" onClick = { connected . addAccountWithSession } />
106
132
) }
0 commit comments