Skip to content

Commit

Permalink
Merge pull request #67 from concord-consortium/187399429-add-delimete…
Browse files Browse the repository at this point in the history
…r-dropdown

feat: Add dropdown for delimiter [PT-187399429]
  • Loading branch information
dougmartin authored Sep 27, 2024
2 parents 369987e + 47fcdd2 commit a1f15be
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type SequenceGroup = {
sequences: Node[][];
};

type DelimiterType = "none"|"space"|"other";

const SequenceOutputHeader = ({ group }: { group: SequenceGroup }) => {
const [expanded, setExpanded] = useState(false);
const startingState = group.startingNode?.label ?? AnyStartingState;
Expand Down Expand Up @@ -142,6 +144,8 @@ export const App = () => {
const [fastSimulation, setFastSimulation] = useState(defaultFastSimulation);
const fastSimulationRef = useRef(false);
const [highlightOutput, setHighlightOutput] = useState<{group: SequenceGroup, sequence: Node[]}|undefined>();
const [delimiterType, setDelimiterType] = useState<DelimiterType>(
delimiter === "" ? "none" : (delimiter === " " ? "space" : "other"));

const handleDimensionChange = ({width, height}: {width: number, height: number}) => {
widthRef.current = width;
Expand Down Expand Up @@ -306,6 +310,20 @@ export const App = () => {
setDelimiter(e.target.value);
};

const handleChangeDelimiterType = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newType = e.target.value as DelimiterType;
setDelimiterType(newType);
switch (newType) {
case "space":
setDelimiter(" ");
break;
case "none":
case "other":
setDelimiter("");
break;
}
};

const handleChangeStartingState = (e: React.ChangeEvent<HTMLSelectElement>) => {
setStartingState(e.target.value);
};
Expand Down Expand Up @@ -373,9 +391,6 @@ export const App = () => {
const onPlayClick = generationMode === "playing"
? handlePause
: (generationMode === "paused" ? handleResume : handlePlay);
const delimiterIsSpace = delimiter === " ";
const delimiterValue = delimiterIsSpace ? "" : delimiter;
const delimiterPlaceholder = delimiterIsSpace ? "(space)" : "(none)";
const sortedNodes = [...graph.nodes];
sortedNodes.sort((a, b) => a.label.localeCompare(a.label));

Expand Down Expand Up @@ -403,13 +418,20 @@ export const App = () => {

<div>
<label>Delimiter:</label>
<input className="bordered" type="text"
<select value={delimiterType} onChange={handleChangeDelimiterType}>
<option value="none">none</option>
<option value="space">space</option>
<option value="other">other ...</option>
</select>
{delimiterType === "other" && <input className="bordered" type="text"
onChange={handleChangeDelimiter}
value={delimiterValue}
placeholder={delimiterPlaceholder}
value={delimiter}
placeholder="delimiter"
maxLength={3}
disabled={animating}
/>
style={{width: 75, marginTop: 5}}
autoFocus={true}
/>}
</div>
</div>

Expand Down

0 comments on commit a1f15be

Please sign in to comment.