1
- import type { EuiBasicTableColumn } from '@elastic/eui' ;
2
- import {
3
- EuiButton ,
4
- EuiButtonIcon ,
5
- EuiCallOut ,
6
- EuiFlexGroup ,
7
- EuiFlexItem ,
8
- EuiInMemoryTable ,
9
- EuiPanel ,
10
- EuiSpacer ,
11
- EuiToolTip ,
12
- } from '@elastic/eui' ;
1
+ import { EuiButton , EuiCallOut , EuiPanel , EuiSpacer } from '@elastic/eui' ;
13
2
import type { ReactNode } from 'react' ;
14
3
import type React from 'react' ;
15
4
import { useCallback , useState } from 'react' ;
16
- import { useListAccounts } from '../../../hooks/list- accounts.jsx' ;
5
+ import { useRemoveAccount , useSaveAccount } from '../../../hooks/accounts.jsx' ;
17
6
import { runInBackground } from '../../../lib/async/run-in-background.js' ;
18
7
import type { Account } from '../../../types/game.types.js' ;
19
8
import type { ModalAddAccountConfirmData } from './modal-add-account.jsx' ;
20
9
import { ModalAddAccount } from './modal-add-account.jsx' ;
21
10
import { ModalEditAccount } from './modal-edit-account.jsx' ;
22
11
import type { ModalRemoveAccountConfirmData } from './modal-remove-account.jsx' ;
23
12
import { ModalRemoveAccount } from './modal-remove-account.jsx' ;
13
+ import { TableListAccounts } from './table-list-accounts.jsx' ;
24
14
25
15
export const SidebarItemAccounts : React . FC = ( ) : ReactNode => {
26
16
const [ showAddAccountModal , setShowAddAccountModal ] = useState ( false ) ;
27
17
const [ showEditAccountModal , setShowEditAccountModal ] = useState ( false ) ;
28
18
const [ showRemoveAccountModal , setShowRemoveAccountModal ] = useState ( false ) ;
29
19
30
- // All accounts to display.
31
- const accounts = useListAccounts ( ) ;
20
+ // Hooks to save and remove accounts.
21
+ const saveAccount = useSaveAccount ( ) ;
22
+ const removeAccount = useRemoveAccount ( ) ;
32
23
33
24
// The contextual account being edited or removed.
34
25
const [ account , setAccount ] = useState < Account > ( ) ;
@@ -67,67 +58,27 @@ export const SidebarItemAccounts: React.FC = (): ReactNode => {
67
58
( data : ModalAddAccountConfirmData ) => {
68
59
closeModals ( ) ;
69
60
runInBackground ( async ( ) => {
70
- await window . api . saveAccount ( {
61
+ await saveAccount ( {
71
62
accountName : data . accountName ,
72
63
accountPassword : data . accountPassword ,
73
64
} ) ;
74
65
} ) ;
75
66
} ,
76
- [ closeModals ]
67
+ [ closeModals , saveAccount ]
77
68
) ;
78
69
79
70
const onAccountRemoveConfirm = useCallback (
80
71
( data : ModalRemoveAccountConfirmData ) => {
81
72
closeModals ( ) ;
82
73
runInBackground ( async ( ) => {
83
- await window . api . removeAccount ( {
74
+ await removeAccount ( {
84
75
accountName : data . accountName ,
85
76
} ) ;
86
77
} ) ;
87
78
} ,
88
- [ closeModals ]
79
+ [ closeModals , removeAccount ]
89
80
) ;
90
81
91
- const columns : Array < EuiBasicTableColumn < Account > > = [
92
- {
93
- field : 'accountName' ,
94
- name : 'Name' ,
95
- dataType : 'string' ,
96
- } ,
97
- {
98
- field : 'actions' ,
99
- name : 'Actions' ,
100
- render : ( _value : unknown , account : Account ) => {
101
- return (
102
- < EuiFlexGroup responsive = { true } gutterSize = "s" alignItems = "center" >
103
- < EuiFlexItem grow = { false } >
104
- < EuiToolTip content = "Change Password" position = "bottom" >
105
- < EuiButtonIcon
106
- aria-label = "Change Password"
107
- iconType = "lock"
108
- // display="base"
109
- color = "warning"
110
- onClick = { ( ) => onEditAccountClick ( account ) }
111
- />
112
- </ EuiToolTip >
113
- </ EuiFlexItem >
114
- < EuiFlexItem grow = { false } >
115
- < EuiToolTip content = "Log Out" position = "bottom" >
116
- < EuiButtonIcon
117
- aria-label = "Log Out"
118
- iconType = "exit"
119
- // display="base"
120
- color = "danger"
121
- onClick = { ( ) => onRemoveAccountClick ( account ) }
122
- />
123
- </ EuiToolTip >
124
- </ EuiFlexItem >
125
- </ EuiFlexGroup >
126
- ) ;
127
- } ,
128
- } ,
129
- ] ;
130
-
131
82
return (
132
83
< EuiPanel >
133
84
< EuiCallOut title = "My Accounts" iconType = "key" size = "s" >
@@ -143,9 +94,10 @@ export const SidebarItemAccounts: React.FC = (): ReactNode => {
143
94
144
95
< EuiSpacer size = "m" />
145
96
146
- { accounts . length > 0 && (
147
- < EuiInMemoryTable items = { accounts } columns = { columns } />
148
- ) }
97
+ < TableListAccounts
98
+ editAccountClick = { onEditAccountClick }
99
+ removeAccountClick = { onRemoveAccountClick }
100
+ />
149
101
150
102
< EuiSpacer size = "m" />
151
103
0 commit comments