1+ <script setup lang="ts">
2+ import {computed , inject , ref } from ' vue'
3+ import {useMatchStateStore } from " @/store/matchState" ;
4+ import type {ControlApi } from " @/providers/controlApi" ;
5+ import TextInput from " @/components/common/TextInput.vue" ;
6+
7+ const store = useMatchStateStore ()
8+ const control = inject <ControlApi >(' control-api' )!
9+
10+ const suggestedStatusMessages = [
11+ ' Vision Problems' ,
12+ ' Rule Discussions' ,
13+ ]
14+
15+ const dialogOpen = ref (false )
16+ const customStatusMessage = ref <string >()
17+
18+ const sendStatusMessage = (value : string ) => {
19+ if (value === store .matchState .statusMessage ) {
20+ return
21+ }
22+ control .SubmitChange ({
23+ origin: " UI" ,
24+ revertible: true ,
25+ change: {
26+ $case: " setStatusMessageChange" ,
27+ setStatusMessageChange: {
28+ statusMessage: value ,
29+ }
30+ }
31+ })
32+ }
33+
34+ const clearStatusMessage = () => {
35+ if (! store .matchState .statusMessage ) {
36+ return
37+ }
38+
39+ control .SubmitChange ({
40+ origin: " UI" ,
41+ revertible: true ,
42+ change: {
43+ $case: " setStatusMessageChange" ,
44+ setStatusMessageChange: {
45+ statusMessage: undefined ,
46+ }
47+ }
48+ })
49+ }
50+
51+ const statusMessageType = computed (() => {
52+ const currentStatusMessage = store .matchState .statusMessage
53+ if (! currentStatusMessage ) {
54+ return ' None'
55+ }
56+ if (suggestedStatusMessages .includes (currentStatusMessage )) {
57+ return currentStatusMessage
58+ }
59+ return ' Custom'
60+ })
61+
62+ const onCustomStatusMessageUpdated = () => {
63+ if (statusMessageType .value !== ' Custom' ) {
64+ return
65+ }
66+ if (customStatusMessage .value ) {
67+ sendStatusMessage (customStatusMessage .value )
68+ } else {
69+ clearStatusMessage ()
70+ }
71+ }
72+
73+ const onCustomStatusMessageSelected = () => {
74+ if (customStatusMessage .value ) {
75+ sendStatusMessage (customStatusMessage .value )
76+ }
77+ }
78+
79+ </script >
80+
81+ <template >
82+ <q-btn
83+ label =" Status Message"
84+ color =" primary"
85+ @click =" dialogOpen = true"
86+ />
87+ <q-dialog v-model =" dialogOpen" >
88+ <q-card class =" q-px-sm q-pb-md" >
89+ <q-card-section class =" row items-center q-pb-none" >
90+ <div class =" text-h6" >Status Message</div >
91+ <q-space />
92+ <q-btn icon =" close" flat round dense v-close-popup />
93+ </q-card-section >
94+
95+ <q-card-section >
96+ The status message will be broadcast and displayed on the status-board.
97+ </q-card-section >
98+
99+ <q-separator />
100+
101+ <q-list >
102+ <q-item tag =" label" v-ripple
103+ v-for =" suggestedMessage in suggestedStatusMessages"
104+ :key =" suggestedMessage" >
105+ <q-item-section avatar >
106+ <q-radio
107+ :model-value =" statusMessageType"
108+ @update:model-value =" sendStatusMessage(suggestedMessage)"
109+ :val =" suggestedMessage"
110+ />
111+ </q-item-section >
112+ <q-item-section >
113+ <q-item-label >{{ suggestedMessage }}</q-item-label >
114+ </q-item-section >
115+ </q-item >
116+
117+ <q-item tag =" label" v-ripple >
118+ <q-item-section avatar >
119+ <q-radio
120+ :model-value =" statusMessageType"
121+ @update:model-value =" onCustomStatusMessageSelected"
122+ val =" Custom"
123+ />
124+ </q-item-section >
125+ <q-item-section >
126+ <q-item-label >Custom</q-item-label >
127+ </q-item-section >
128+ </q-item >
129+
130+ <q-item >
131+ <q-item-section avatar >
132+ <TextInput
133+ label =" Custom Status Message"
134+ v-model =" customStatusMessage"
135+ @focusout =" onCustomStatusMessageUpdated"
136+ :clearable =" false"
137+ />
138+ </q-item-section >
139+ </q-item >
140+ </q-list >
141+
142+ <q-card-actions >
143+ <q-btn
144+ v-close-popup
145+ label =" Close"
146+ color =" primary"
147+ />
148+ <q-btn
149+ label =" Clear"
150+ color =" primary"
151+ @click =" clearStatusMessage"
152+ />
153+ </q-card-actions >
154+ </q-card >
155+ </q-dialog >
156+ </template >
157+
158+ <style scoped>
159+
160+ </style >
0 commit comments