@@ -7,19 +7,30 @@ import { type TestInput, type TestOutput } from '@regexplanet/common';
7
7
import { useRouter } from 'next/navigation' ;
8
8
import { formDataToTestInput } from '@/functions/formDataToTestInput' ;
9
9
import { runTestPage } from './runTestPage' ;
10
+ import Link from 'next/link' ;
10
11
11
12
type TestFormProps = {
12
13
engine : RegexEngine ;
13
14
testUrl : string ;
14
15
testInput : TestInput ;
15
16
testOutput : TestOutput | null ;
17
+ inputRows : React . JSX . Element [ ] ;
16
18
}
17
19
18
20
const pendingTestOutput : TestOutput = {
19
21
success : true ,
20
22
html : `<p><img src="/images/spinner.gif" alt="spinner" /> Running, please wait...</p>` ,
21
23
} ;
22
24
25
+ function testInputToSearchParams ( testInput : TestInput ) : URLSearchParams {
26
+ const searchParams = new URLSearchParams ( ) ;
27
+ searchParams . set ( 'regex' , testInput . regex ) ;
28
+ searchParams . set ( 'replacement' , testInput . replacement ) ;
29
+ testInput . options . forEach ( option => searchParams . append ( 'option' , option ) ) ;
30
+ testInput . inputs . forEach ( input => searchParams . append ( 'input' , input ) ) ;
31
+ return searchParams ;
32
+ }
33
+
23
34
function setTestInput ( testInput : TestInput ) : string {
24
35
const searchParams = new URLSearchParams ( ) ;
25
36
searchParams . set ( 'regex' , testInput . regex ) ;
@@ -40,12 +51,7 @@ export default function TestForm(props: TestFormProps) {
40
51
//const [testInput, setTestInput] = useState<TestInput>(props.testInput);
41
52
const testInput = props . testInput ;
42
53
43
- const inputRows = testInput . inputs . map ( ( input , index ) => (
44
- < div className = "mb-2" key = { `ikey${ index } ` } >
45
- < input type = "text" className = "form-control" id = { `input${ index } ` } name = "input" defaultValue = { input } />
46
- </ div >
47
- ) ) ;
48
- console . log ( "render" , testInput . inputs ) ;
54
+ const inputRows = props . inputRows ;
49
55
50
56
const onClearResults = ( ) => {
51
57
setTestOutput ( null ) ;
@@ -96,7 +102,8 @@ export default function TestForm(props: TestFormProps) {
96
102
}
97
103
console . log ( "after more" , localInput . inputs ) ;
98
104
99
- router . push ( setTestInput ( localInput ) ) ;
105
+ router . replace ( setTestInput ( localInput ) ) ;
106
+ router . refresh ( ) ;
100
107
}
101
108
102
109
const onFewerInputs = ( event : React . MouseEvent < HTMLButtonElement > ) => {
@@ -114,7 +121,8 @@ export default function TestForm(props: TestFormProps) {
114
121
localInput . inputs . push ( '' ) ;
115
122
}
116
123
console . log ( "after fewer" , localInput . inputs ) ;
117
- router . push ( setTestInput ( localInput ) ) ;
124
+ router . replace ( setTestInput ( localInput ) ) ;
125
+ router . refresh ( ) ;
118
126
} ;
119
127
120
128
const onSwitchEngines = ( event : React . MouseEvent < HTMLButtonElement > ) => {
@@ -162,9 +170,10 @@ export default function TestForm(props: TestFormProps) {
162
170
< h2 className = "pt-3" > Inputs</ h2 >
163
171
{ inputRows }
164
172
< button type = "submit" className = "btn btn-primary" > Test</ button >
165
- < button className = "ms-3 btn btn-outline-primary" onClick = { onMoreInputs } > More inputs</ button >
166
- { testInput . inputs . length > 5 ? < button className = "ms-3 btn btn-outline-primary" onClick = { onFewerInputs } > Fewer inputs</ button > : null }
167
- < button type = "submit" className = "btn btn-outline-primary float-end" onClick = { onSwitchEngines } > Switch Engines</ button >
173
+ < button className = "ms-3 btn btn-outline-primary scripting-required" onClick = { onMoreInputs } > More inputs</ button >
174
+ { testInput . inputs . length > 5 ? < button className = "ms-3 btn btn-outline-primary scripting-required" onClick = { onFewerInputs } > Fewer inputs</ button > : null }
175
+ < button type = "submit" className = "btn btn-outline-primary float-end scripting-required" onClick = { onSwitchEngines } > Switch Engines</ button >
176
+ < Link className = "btn btn-outline-primary float-end noscript-only" href = { `/advanced/select.html?${ testInputToSearchParams ( testInput ) . toString ( ) } ` } > Switch Engines</ Link >
168
177
</ form >
169
178
</ >
170
179
) ;
0 commit comments