9
9
ScriptItemBase ,
10
10
ScriptOption ,
11
11
} from 'shared/types'
12
- import { useState , useEffect } from 'react'
12
+ import { useState , useEffect , useRef , useMemo } from 'react'
13
13
import { useWindowStore } from 'renderer/store'
14
14
import {
15
15
findValue ,
@@ -44,11 +44,21 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
44
44
const [ submitInProgress , setSubmitInProgress ] = useState ( false )
45
45
const [ error , setError ] = useState ( false )
46
46
const [ canRunJob , setCanRunJob ] = useState ( false )
47
+ const submitButtonRef = useRef ( null )
47
48
48
49
let required = getAllRequired ( script )
49
50
let optional = getAllOptional ( script )
50
51
const { settings } = useWindowStore ( )
51
52
53
+ useMemo ( ( ) => {
54
+ App . onScriptFormSubmit ( 'submit-script-form' , async ( ) => {
55
+ // console.log("SUBMIT script form for ", job.script.id)
56
+ if ( submitButtonRef && submitButtonRef . current ) {
57
+ submitButtonRef . current . click ( )
58
+ }
59
+ } )
60
+ } , [ ] )
61
+
52
62
useEffect ( ( ) => {
53
63
setCanRunJob ( settings . downloadFolder ?. trim ( ) != '' )
54
64
} , [ settings . downloadFolder ] )
@@ -65,8 +75,9 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
65
75
// - page-width
66
76
// - page-height
67
77
68
- const is2StepsJob =
69
- optional . findIndex ( ( item ) => item . name === 'stylesheet-parameters' ) > - 1
78
+ // moved to job datatype
79
+ // const is2StepsJob =
80
+ // optional.findIndex((item) => item.name === 'stylesheet-parameters') > -1
70
81
// Filter out the options that are to be defined in the first step of braille script
71
82
const filteredOptions = [
72
83
'stylesheet' ,
@@ -77,7 +88,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
77
88
'tts' ,
78
89
]
79
90
const hiddenOptions = [ 'transform' , 'stylesheet-parameters' ]
80
- if ( is2StepsJob ) {
91
+ if ( job . is2StepsJob ) {
81
92
optional = optional . filter ( ( item ) =>
82
93
filteredOptions . includes ( item . name )
83
94
)
@@ -96,7 +107,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
96
107
// When this property is set
97
108
// 'optional' is what is displayed on screen as optional values. they could technically be job inputs, options, or stylesheet parameters
98
109
// but the user input values aren't stored there, those go in the job request itself
99
- if ( is2StepsJob && job . stylesheetParameters != null ) {
110
+ if ( job . is2StepsJob && job . stylesheetParameters != null ) {
100
111
required = [ ]
101
112
optional = [
102
113
...getAllOptional ( script )
@@ -176,7 +187,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
176
187
// submit a job
177
188
let onSubmit = async ( e ) => {
178
189
e . preventDefault ( )
179
- if ( is2StepsJob && job . stylesheetParameters == null ) {
190
+ if ( job . is2StepsJob && job . stylesheetParameters == null ) {
180
191
/* constraints on the stylesheet parameters :
181
192
the /stylesheet-parameters call should not be made if
182
193
- TTS is disabled (audio = false) on scripts dtbook-to-daisy3, dtbook-to-epub3 and zedai-to-epub3
@@ -206,7 +217,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
206
217
}
207
218
} else {
208
219
let options = [ ...job . jobRequest . options ]
209
- if ( is2StepsJob ) {
220
+ if ( job . is2StepsJob ) {
210
221
// format all the stylesheet parameter options as a string
211
222
// and assign it to the 'stylesheet-parameters' option
212
223
let stylesheetParametersOption =
@@ -411,20 +422,21 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
411
422
</ div >
412
423
) }
413
424
< div className = "form-buttons" >
414
- { is2StepsJob && job . stylesheetParameters != null && (
425
+ { job . is2StepsJob && job . stylesheetParameters != null && (
415
426
< button className = "run" onClick = { previous } >
416
427
Back
417
428
</ button >
418
429
) }
419
- { is2StepsJob && job . stylesheetParameters == null ? (
420
- < button className = "run" type = "submit" >
430
+ { job . is2StepsJob && job . stylesheetParameters == null ? (
431
+ < button className = "run" type = "submit" ref = { submitButtonRef } >
421
432
Next
422
433
</ button >
423
434
) : (
424
435
< button
425
436
className = "run"
426
437
type = "submit"
427
438
disabled = { ! canRunJob || submitInProgress }
439
+ ref = { submitButtonRef }
428
440
>
429
441
{ submitInProgress ? 'Starting...' : 'Run' }
430
442
</ button >
0 commit comments