@@ -9,10 +9,14 @@ import {
9
9
EuiToolTip ,
10
10
} from '@elastic/eui' ;
11
11
import groupBy from 'lodash-es/groupBy.js' ;
12
+ import isEqual from 'lodash-es/isEqual.js' ;
12
13
import isNil from 'lodash-es/isNil.js' ;
13
14
import type { ReactElement , ReactNode } from 'react' ;
14
15
import { Fragment , memo , useMemo } from 'react' ;
15
- import { useListCharacters } from '../../../hooks/characters.jsx' ;
16
+ import {
17
+ useGetPlayingCharacter ,
18
+ useListCharacters ,
19
+ } from '../../../hooks/characters.jsx' ;
16
20
import { GameCodeLabels } from '../../../lib/game/game-code-labels.js' ;
17
21
import type { Character } from '../../../types/game.types.js' ;
18
22
@@ -24,6 +28,7 @@ interface TableByGameCode {
24
28
25
29
export interface TableListCharactersProps {
26
30
onPlayCharacterClick : ( character : Character ) => void ;
31
+ onQuitCharacterClick : ( character : Character ) => void ;
27
32
onEditCharacterClick : ( character : Character ) => void ;
28
33
onRemoveCharacterClick : ( character : Character ) => void ;
29
34
}
@@ -32,13 +37,17 @@ export const TableListCharacters: React.FC<TableListCharactersProps> = memo(
32
37
( props : TableListCharactersProps ) : ReactNode => {
33
38
const {
34
39
onPlayCharacterClick,
40
+ onQuitCharacterClick,
35
41
onEditCharacterClick,
36
42
onRemoveCharacterClick,
37
43
} = props ;
38
44
39
45
// All characters to display.
40
46
const characters = useListCharacters ( ) ;
41
47
48
+ // Which character is currently being played?
49
+ const playingCharacter = useGetPlayingCharacter ( ) ;
50
+
42
51
// We'll display the characters grouped by game code.
43
52
const charactersByGameCode = useMemo ( ( ) => {
44
53
return groupBy ( characters , 'gameCode' ) ;
@@ -70,15 +79,27 @@ export const TableListCharacters: React.FC<TableListCharactersProps> = memo(
70
79
alignItems = "center"
71
80
>
72
81
< EuiFlexItem grow = { false } >
73
- < EuiToolTip content = "Play" position = "bottom" >
74
- < EuiButtonIcon
75
- aria-label = "Play"
76
- iconType = "play"
77
- display = "base"
78
- color = "success"
79
- onClick = { ( ) => onPlayCharacterClick ( character ) }
80
- />
81
- </ EuiToolTip >
82
+ { isEqual ( playingCharacter , character ) ? (
83
+ < EuiToolTip content = "Quit" position = "bottom" >
84
+ < EuiButtonIcon
85
+ aria-label = "Quit"
86
+ iconType = "stopFilled"
87
+ display = "base"
88
+ color = "accent"
89
+ onClick = { ( ) => onQuitCharacterClick ( character ) }
90
+ />
91
+ </ EuiToolTip >
92
+ ) : (
93
+ < EuiToolTip content = "Play" position = "bottom" >
94
+ < EuiButtonIcon
95
+ aria-label = "Play"
96
+ iconType = "playFilled"
97
+ display = "base"
98
+ color = "success"
99
+ onClick = { ( ) => onPlayCharacterClick ( character ) }
100
+ />
101
+ </ EuiToolTip >
102
+ ) }
82
103
</ EuiFlexItem >
83
104
< EuiFlexItem grow = { false } >
84
105
< EuiToolTip content = "Edit" position = "bottom" >
@@ -107,7 +128,13 @@ export const TableListCharacters: React.FC<TableListCharactersProps> = memo(
107
128
} ,
108
129
} ,
109
130
] ;
110
- } , [ onPlayCharacterClick , onEditCharacterClick , onRemoveCharacterClick ] ) ;
131
+ } , [
132
+ playingCharacter ,
133
+ onPlayCharacterClick ,
134
+ onQuitCharacterClick ,
135
+ onEditCharacterClick ,
136
+ onRemoveCharacterClick ,
137
+ ] ) ;
111
138
112
139
// Create a table for each game code that has characters.
113
140
const tablesByGameCode = useMemo < Array < TableByGameCode > > ( ( ) => {
0 commit comments