Skip to content

Commit 305588d

Browse files
committed
Created dummy integer input component
1 parent ea89201 commit 305588d

File tree

9 files changed

+85
-18
lines changed

9 files changed

+85
-18
lines changed

solves/base-template/internals/global.d.ts.ejs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,32 @@ declare module '*.lp' {
3636
* General
3737
*/
3838

39-
type BaseInputKeys = <%-
40-
Object.entries(inputBase).map(([k, v]) =>
41-
`"${k}"`
42-
).join(" | ")
39+
<%-
40+
(!Object.keys(inputBase).length) ? "" :
41+
"type BaseInputKeys = " +
42+
Object.entries(inputBase).map(([k, v]) =>
43+
`"${k}"`
44+
).join(" | ")
4345
-%>;
44-
type ConstrainedInputKeys = <%-
45-
Object.entries(inputConstrained).map(([k, v]) =>
46-
`"${k}"`
47-
).join(" | ")
46+
<%-
47+
(!Object.keys(inputInteger).length) ? "" :
48+
"type IntegerInputKeys = " +
49+
Object.entries(inputInteger).map(([k, v]) =>
50+
`"${k}"`
51+
).join(" | ")
4852
-%>;
49-
type AllInputKeys = BaseInputKeys | ConstrainedInputKeys;
53+
<%-
54+
(!Object.keys(inputConstrained).length) ? "" :
55+
"type ConstrainedInputKeys = " +
56+
Object.entries(inputConstrained).map(([k, v]) =>
57+
`"${k}"`
58+
).join(" | ")
59+
-%>;
60+
type AllInputKeys = BaseInputKeys | IntegerInputKeys | ConstrainedInputKeys;
5061

5162
type OutputKeys = <%-
52-
Object.entries(output).map(([k, v]) =>
53-
`"${k}"`
54-
).join(" | ")
63+
Object.entries(output).map(([k, v]) =>
64+
`"${k}"`
65+
).join(" | ")
5566
-%>;
5667

solves/base-template/src/components/App.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
width: 100%;
99
}
1010

11-
.text-input-wrapper {
11+
.input-wrapper {
1212
flex: 1 0 0;
1313

1414
min-width: 12em;
1515
/*border: thin solid black;*/
1616
}
17-
.text-input-wrapper > * {
17+
.input-wrapper > * {
1818
width: 100%;
1919
}
2020

solves/base-template/src/components/App.tsx.ejs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22

3+
import {IntegerInput} from "./IntegerInput";
34
import {LineHighlighterTextbox} from "./generic/LineHighlighterTextbox";
45
import {ResultDisplay} from "./ResultDisplay";
56

@@ -83,23 +84,41 @@ export class App extends React.Component<{}, State> {
8384
const recalcCallback = async () => this._recalculateOutputs();
8485

8586
<%-
86-
Object.entries(allInputs).map(([k, v]) => {
87+
Object.entries(allTextInputs).map(([k, v]) => {
8788
const x = {};
8889
x.stateValue = "input" + upperCaseFirst(k);
8990
x.onChangeFnName = "set" + upperCaseFirst(k);
90-
return ht.onChangeHelpers(x);
91+
return ht.onChangeHelper(x);
92+
}).join("")
93+
-%>
94+
<%-
95+
Object.entries(allNumericInputs).map(([k, v]) => {
96+
const x = {};
97+
x.stateValue = "input" + upperCaseFirst(k);
98+
x.onChangeFnName = "set" + upperCaseFirst(k);
99+
return ht.onChangeHelperNumeric(x);
91100
}).join("")
92101
-%>
93102

94103
return <div id="app">
95104
<%-
96-
Object.entries(allInputs).map(([k, v]) => {
105+
Object.entries(allTextInputs).map(([k, v]) => {
97106
const x = {};
98107
x.inputID = k;
99108
x.title = v.title;
100109
return ht.jsxInputComponent(x);
101110
}).join("")
102111
-%>
112+
<%-
113+
Object.entries(inputInteger).map(([k, v]) => {
114+
const x = {};
115+
x.inputID = k;
116+
x.title = v.title;
117+
x.min = v.min;
118+
x.max = v.max;
119+
return ht.jsxInputIntegerComponent(x);
120+
}).join("")
121+
-%>
103122
<%-
104123
Object.entries(output).map(([k, v]) => {
105124
const x = {};

solves/base-template/src/components/App.tsx.ejshelpers/jsxInputComponent.tsx.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div className="text-input-wrapper">
1+
<div className="input-wrapper">
22
<LineHighlighterTextbox
33
label="<%- title %>"
44
initialValue={this.state.input<%- upperCaseFirst(inputID) %>}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div className="input-wrapper">
2+
<IntegerInput
3+
label="<%- title %>"
4+
min={<%- min %>}
5+
max={<%- max %>}
6+
value={this.state.input<%- upperCaseFirst(inputID) %>}
7+
invalidLines={
8+
this.state.invalidInputs.get("<%- inputID %>") || new Set()
9+
}
10+
onChange={set<%- upperCaseFirst(inputID) %>}
11+
/>
12+
</div>

solves/base-template/src/components/App.tsx.ejshelpers/onChangeHelpers.tsx.ejs renamed to solves/base-template/src/components/App.tsx.ejshelpers/onChangeHelper.tsx.ejs

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const <%- onChangeFnName %> = async (value: number) => {
2+
this.setState({<%- stateValue %>: value}, recalcCallback);
3+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from "react";
2+
3+
interface Props {
4+
label: string;
5+
min: number;
6+
max: number;
7+
value: number;
8+
invalidLines: Set<string>;
9+
onChange: (value: number) => Promise<void>;
10+
}
11+
12+
//interface State {
13+
// // Nothing for now
14+
//}
15+
16+
export function IntegerInput(props: Props) {
17+
return <>
18+
{props.label}
19+
</>;
20+
}
21+

solves/base-template/src/runSolver/index.ts.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export async function runSolver(params: SolverParameters): Promise<SolverResult>
174174
problemInstance,
175175
logicSpecStr,
176176
].join("\n\n");
177+
console.log(fullQuery);
177178
return runClingo(fullQuery);
178179
} else {
179180
return null;

0 commit comments

Comments
 (0)