Skip to content

Commit 06303ab

Browse files
committed
Sharing working, including selecting which engine
1 parent 6dcb001 commit 06303ab

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/app/share/index.html/PreviewRegex.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { type TestInput } from "@regexplanet/common";
22
import { SubmitButton } from '@/components/SubmitButton';
3-
import { getWorkingEngine, getWorkingEngineOrThrow } from '@/engines';
3+
import { getWorkingEngines } from '@/engines';
44

55
type PreviewRegexProps = {
66
theShare: TestInput;
77
}
88

99
export function PreviewRegex( {theShare}: PreviewRegexProps) {
10-
const engineCode = theShare.engine;
11-
let theEngine = getWorkingEngine(engineCode);
12-
if (!theEngine) {
13-
theEngine = getWorkingEngineOrThrow("java");
14-
}
10+
11+
theShare.engine = theShare.engine || 'java';
12+
13+
const options = theShare.options.map((option, index) => { return (<input type="hidden" name="option" key={`option_${index}`} value={option} />); });
14+
const inputs = theShare.inputs.map((input, index) => { return (<input type="hidden" key={`input_${index}`} name="input" value={input} />) });
1515
return (
1616
<>
17-
<form action={`/advanced/${theEngine.handle}/index.html`} className="" method="post">
1817
<div className="mb-3">
1918
<label htmlFor="regex" className="form-label">Regular Expression</label>
2019
<input type="text" className="form-control" id="regex" name="regex" defaultValue={theShare.regex} />
@@ -23,8 +22,18 @@ export function PreviewRegex( {theShare}: PreviewRegexProps) {
2322
<label htmlFor="replacement" className="form-label">Replacement</label>
2423
<input type="text" className="form-control" id="replacement" name="replacement" defaultValue={theShare.replacement} />
2524
</div>
26-
<SubmitButton>{`Test with ${theEngine.short_name}`}</SubmitButton>
27-
</form>
25+
<div className="mb-3">
26+
<label className="form-label d-block">Test with:</label>
27+
{ getWorkingEngines().map((theEngine, index) => { return (
28+
<form action={`/advanced/${theEngine.handle}/index.html`} className="d-inline-block m-1" key={`form_${index}`} method="get">
29+
<input type="hidden" name="engine" value={theEngine.handle} />
30+
<input type="hidden" name="regex" value={theShare.regex} />
31+
<input type="hidden" name="replacement" value={theShare.replacement} />
32+
{options}
33+
{inputs}
34+
<button className={`btn ${theShare.engine == theEngine.handle ? 'btn-primary' : 'btn-outline-primary'}`}>{`${theEngine.short_name}`}</button>
35+
</form>) })}
36+
</div>
2837
<details className="mt-3"><summary>Raw data</summary><pre>{JSON.stringify(theShare, null, 2)}</pre></details>
2938
</>
3039
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy