Skip to content

Commit 73aa453

Browse files
fix(#243, #244): menu actions run and next behave like the form
1 parent 7b10c8d commit 73aa453

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

src/main/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function buildMenu() {
151151
store.dispatch(selectJob(job))
152152
},
153153
onRunJob: async (job) => {
154-
MainWindow().then((w) => w.webContents.send('run-job'))
154+
MainWindow().then((w) => w.webContents.send('submit-script-form'))
155155
// store.dispatch(
156156
// runJob({
157157
// ...job,

src/main/menu.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export function buildMenuTemplate({
6464
.replace(' - App', '')
6565
.replace('(2023)', '')
6666
.trim()
67+
let submitFormLabel =
68+
currentJob &&
69+
currentJob.is2StepsJob &&
70+
currentJob.stylesheetParameters == null
71+
? 'Next'
72+
: 'Run job'
6773

6874
// @ts-ignore
6975
const template: MenuItemConstructorOptions = [
@@ -123,7 +129,7 @@ export function buildMenuTemplate({
123129
: []),
124130
{ type: 'separator' },
125131
{
126-
label: 'Run job',
132+
label: submitFormLabel,
127133
click: () => {
128134
onRunJob(currentJob)
129135
},

src/renderer/bridge/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const API = {
4545
copyToClipboard: ipcs.copyToClipboard,
4646
log: ipcs.log,
4747
oneTimeFetch: ipcs.oneTimeFetch,
48+
onScriptFormSubmit: (channel, listener) => ipcRenderer.on(channel, listener),
4849
// we can add on to this API and restructure it as we move more commands to the redux side
4950
store: {
5051
dispatch,

src/renderer/components/NewJobPane/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
setSponsorshipMessageLastShown,
1717
} from 'shared/data/slices/settings'
1818
import { externalLinkClick } from 'renderer/utils'
19+
import * as utils from '../../utils'
1920

2021
const { App } = window
2122

@@ -24,8 +25,7 @@ import {
2425
updateSponsorshipMessage,
2526
} from '../../utils'
2627

27-
// is datestring more than 2 weeks old
28-
// datestring is milliseconds (string)
28+
// is dateInMs more than 2 weeks old
2929
let isExpired = (dateInMs: number) => {
3030
if (dateInMs == 0) return true
3131

@@ -70,6 +70,7 @@ export function NewJobPane({ job }: { job: Job }) {
7070
updateJob({
7171
...job,
7272
script: selection,
73+
is2StepsJob: utils.is2StepsScript(selection),
7374
jobData: {
7475
...job.jobData,
7576
nicename: selection.nicename,

src/renderer/components/ScriptForm/index.tsx

+22-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ScriptItemBase,
1010
ScriptOption,
1111
} from 'shared/types'
12-
import { useState, useEffect } from 'react'
12+
import { useState, useEffect, useRef, useMemo } from 'react'
1313
import { useWindowStore } from 'renderer/store'
1414
import {
1515
findValue,
@@ -44,11 +44,21 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
4444
const [submitInProgress, setSubmitInProgress] = useState(false)
4545
const [error, setError] = useState(false)
4646
const [canRunJob, setCanRunJob] = useState(false)
47+
const submitButtonRef = useRef(null)
4748

4849
let required = getAllRequired(script)
4950
let optional = getAllOptional(script)
5051
const { settings } = useWindowStore()
5152

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+
5262
useEffect(() => {
5363
setCanRunJob(settings.downloadFolder?.trim() != '')
5464
}, [settings.downloadFolder])
@@ -65,8 +75,9 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
6575
// - page-width
6676
// - page-height
6777

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
7081
// Filter out the options that are to be defined in the first step of braille script
7182
const filteredOptions = [
7283
'stylesheet',
@@ -77,7 +88,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
7788
'tts',
7889
]
7990
const hiddenOptions = ['transform', 'stylesheet-parameters']
80-
if (is2StepsJob) {
91+
if (job.is2StepsJob) {
8192
optional = optional.filter((item) =>
8293
filteredOptions.includes(item.name)
8394
)
@@ -96,7 +107,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
96107
// When this property is set
97108
// 'optional' is what is displayed on screen as optional values. they could technically be job inputs, options, or stylesheet parameters
98109
// 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) {
100111
required = []
101112
optional = [
102113
...getAllOptional(script)
@@ -176,7 +187,7 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
176187
// submit a job
177188
let onSubmit = async (e) => {
178189
e.preventDefault()
179-
if (is2StepsJob && job.stylesheetParameters == null) {
190+
if (job.is2StepsJob && job.stylesheetParameters == null) {
180191
/* constraints on the stylesheet parameters :
181192
the /stylesheet-parameters call should not be made if
182193
- 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 }) {
206217
}
207218
} else {
208219
let options = [...job.jobRequest.options]
209-
if (is2StepsJob) {
220+
if (job.is2StepsJob) {
210221
// format all the stylesheet parameter options as a string
211222
// and assign it to the 'stylesheet-parameters' option
212223
let stylesheetParametersOption =
@@ -411,20 +422,21 @@ export function ScriptForm({ job, script }: { job: Job; script: Script }) {
411422
</div>
412423
)}
413424
<div className="form-buttons">
414-
{is2StepsJob && job.stylesheetParameters != null && (
425+
{job.is2StepsJob && job.stylesheetParameters != null && (
415426
<button className="run" onClick={previous}>
416427
Back
417428
</button>
418429
)}
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}>
421432
Next
422433
</button>
423434
) : (
424435
<button
425436
className="run"
426437
type="submit"
427438
disabled={!canRunJob || submitInProgress}
439+
ref={submitButtonRef}
428440
>
429441
{submitInProgress ? 'Starting...' : 'Run'}
430442
</button>

src/renderer/utils/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ export function externalLinkClick(e, app) {
8787
app.openInBrowser(closest.href)
8888
}
8989
}
90+
91+
export function is2StepsScript(script: Script) {
92+
return (
93+
script.options.findIndex(
94+
(item) => item.name == 'stylesheet-parameters'
95+
) > -1
96+
)
97+
}

src/shared/types/pipeline.ts

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export type Job = {
211211
* from the pipeline stylesheet-parameters end point and stored here.
212212
*/
213213
stylesheetParameters?: ScriptOption[]
214+
is2StepsJob?: boolean
214215
}
215216
// JobData is the JSON representation of Pipeline WS data for a single job
216217
export type JobData = {

0 commit comments

Comments
 (0)