Skip to content

Commit ef11aa7

Browse files
fix(#235): tts connection messages and fields
Fields are required in the HTML form. If a field is invalid (empty) then the connection error messages aren't shown; it just says that the field is required.
1 parent 1832ac6 commit ef11aa7

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

src/renderer/components/TtsEnginesConfig/index.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,27 @@ export function TtsEnginesConfigPane({
5858
[engineKey: string]: string
5959
}>({})
6060

61+
const [engineStatus, setEngineStatus] = useState<{
62+
[engineKey: string]: string
63+
}>({})
64+
6165
const [enginePropsChanged, setEnginePropsChanged] = useState<{
6266
[engineKey: string]: boolean
6367
}>({})
6468

6569
useEffect(() => {
6670
let messages = { ...engineMessage }
67-
71+
let statuses = { ...engineStatus }
6872
for (let engineKey in pipeline.ttsEnginesStates) {
6973
// Note : engineKey in template is the full one
7074
// while in voices only the final name is given
7175
messages['org.daisy.pipeline.tts.' + engineKey] =
7276
pipeline.ttsEnginesStates[engineKey].message
77+
statuses['org.daisy.pipeline.tts.' + engineKey] =
78+
pipeline.ttsEnginesStates[engineKey].status
7379
}
7480
setEngineMessage(messages)
81+
setEngineStatus(statuses)
7582
}, [pipeline.ttsEnginesStates])
7683

7784
let onPropertyChange = (e, propName) => {
@@ -142,7 +149,7 @@ export function TtsEnginesConfigPane({
142149
// TODO : add a setting to let users disable autoconnect on startup
143150
onChangeTtsEngineProperties(ttsProps)
144151
}
145-
152+
console.log(engineProperties)
146153
return (
147154
<>
148155
<p id="available-voices-label" className="label">
@@ -180,22 +187,32 @@ export function TtsEnginesConfigPane({
180187
)
181188
})()}
182189
</label>
183-
<input
184-
id={propkey}
185-
type="text"
186-
onChange={(e) =>
187-
onPropertyChange(e, propkey)
188-
}
189-
value={
190-
engineProperties.find(
191-
(p) => p.key == propkey
192-
)?.value ?? ''
193-
}
194-
/>
190+
<div className="input">
191+
<input
192+
id={propkey}
193+
type="text"
194+
onChange={(e) =>
195+
onPropertyChange(e, propkey)
196+
}
197+
value={
198+
engineProperties.find(
199+
(p) => p.key == propkey
200+
)?.value ?? ''
201+
}
202+
required
203+
/>
204+
{!(engineProperties.find(
205+
(p) => p.key == propkey
206+
)?.value) && (
207+
<span className="required-field-message">
208+
This field is required
209+
</span>
210+
)}
211+
</div>
195212
</li>
196213
))}
197214
{engineMessage[engineId] && (
198-
<li className="error">
215+
<li className={engineStatus[engineId]}>
199216
{engineMessage[engineId].split('\n')
200217
.length === 1 ? (
201218
<span>{engineMessage[engineId]}</span>

src/renderer/style/settings.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ $engineColWidth: 8rem;
222222
gap: calc(var(--pad) * 1.5);
223223
margin-top: calc(var(--pad) * 1);
224224
padding: 0;
225+
/* don't show engine messages if the engine is disabled. they don't make sense. */
226+
li:has(input:invalid) .disabled {
227+
display: none;
228+
}
225229
&>li {
226230
font-weight: bold;
227231
font-size: larger;
@@ -236,21 +240,28 @@ $engineColWidth: 8rem;
236240
display: flex;
237241
flex-direction: row;
238242

239-
:first-child {
243+
label {
240244
width: 5rem;
241245
}
242-
:last-child {
246+
button, .input, .input input {
243247
width: 70%;
244248
}
245249
}
246-
.error {
250+
.required-field-message, .error, .disabled {
251+
font-style: italic;
252+
font-weight: normal;
253+
color: var(--warning);
247254
details {
248255
width:100% !important;
249256
summary {
250257
width:100% !important;
251258
}
252259
}
253260
}
261+
.connecting {
262+
font-style: italic;
263+
font-weight: normal;
264+
}
254265
}
255266
}
256267

@@ -262,6 +273,9 @@ $engineColWidth: 8rem;
262273
.Disconnected::after {
263274
content: '';
264275
}
276+
.required-field-message {
277+
display: block;
278+
}
265279
}
266280
.tts-more-options {
267281
display: flex;

0 commit comments

Comments
 (0)