Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disable inputs while animating [PT-187393298] #57

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ export const App = () => {
}, [setFastSimulation]);

const uiForGenerate = () => {
const disabled = graphEmpty;
const playLabel = generationMode === "playing" ? "Pause" : (generationMode === "paused" ? "Resume" : "Play");
const PlayOrPauseIcon = generationMode === "playing" ? PauseIcon : PlayIcon;
const onPlayClick = generationMode === "playing"
Expand All @@ -357,7 +356,7 @@ export const App = () => {
<div className="flex-col">
<div>
<label>Starting State:</label>
<select onChange={handleChangeStartingState} value={startingState} disabled={disabled}>
<select onChange={handleChangeStartingState} value={startingState} disabled={animating}>
<option value="">{AnyStartingState}</option>
{sortedNodes.map(n => <option key={n.id} value={n.id}>{n.label}</option>)}
</select>
Expand All @@ -370,7 +369,7 @@ export const App = () => {
value={lengthLimit}
onChange={handleChangeLengthLimit}
min={1}
disabled={disabled}
disabled={animating}
/>
</div>

Expand All @@ -381,26 +380,26 @@ export const App = () => {
value={delimiterValue}
placeholder={delimiterPlaceholder}
maxLength={3}
disabled={disabled}
disabled={animating}
/>
</div>
</div>

<SpeedToggle fastSimulation={fastSimulation} onChange={handleSpeedToggle} />
<SpeedToggle fastSimulation={fastSimulation} onChange={handleSpeedToggle} disabled={animating} />

</div>
<div className="buttons">
<button
type="button"
onClick={onPlayClick}
disabled={disabled || lengthLimit === undefined}>
disabled={graphEmpty || lengthLimit === undefined}>
<PlayOrPauseIcon />
{playLabel}
</button>
<button
type="button"
onClick={handleStep}
disabled={disabled || lengthLimit === undefined || generationMode === "playing"}>
disabled={graphEmpty || lengthLimit === undefined || generationMode === "playing"}>
<StepIcon />
Step
</button>
Expand Down
2 changes: 2 additions & 0 deletions src/components/dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const Dataset = (props: Props) => {
return (
<div className="dataset">
<Toolbar
disabled={animating}
tools={["home"]}
onToolSelected={handleToolSelected}
onReset={onReset}
Expand All @@ -63,6 +64,7 @@ export const Dataset = (props: Props) => {
return (
<div className="dataset">
<Toolbar
disabled={animating}
tools={["select","fitView","recenter","reset","home"]}
onToolSelected={handleToolSelected}
onReset={onReset}
Expand Down
9 changes: 8 additions & 1 deletion src/components/drawing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const Drawing = (props: Props) => {
return (
<div className="drawing">
<Toolbar
disabled={animating}
tools={tools}
onToolSelected={handleToolSelected}
onReset={onReset}
Expand Down Expand Up @@ -337,7 +338,13 @@ export const Drawing = (props: Props) => {
onChange={handleChangeNode}
onCancel={handleClearSelectedNode}
/>
<AddText ref={textAreaRef} visible={drawingMode === "addText"} width={addTextWidth} onChange={handleTextChange} />
<AddText
ref={textAreaRef}
visible={drawingMode === "addText"}
width={addTextWidth}
disabled={animating}
onChange={handleTextChange}
/>
</div>
);
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/drawing/add-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { clsx } from "clsx";
import "./add-text.scss";

interface Props {
disabled: boolean;
visible: boolean;
width: number;
onChange: (newText: string) => void
Expand All @@ -12,14 +13,14 @@ interface Props {
// eslint-disable-next-line max-len
const placeholder = "Create a Markov chain by typing or pasting text here. WARNING: your current Markov chain will be overwritten.";

export const AddText = forwardRef<HTMLTextAreaElement, Props>(({visible, width, onChange}: Props, ref) => {
export const AddText = forwardRef<HTMLTextAreaElement, Props>(({disabled, visible, width, onChange}: Props, ref) => {
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
onChange(e.currentTarget.value.trim());
};

return (
<div className={clsx("addText", {visible})} style={{width}}>
<textarea ref={ref} placeholder={placeholder} onChange={handleChange} />
<textarea ref={ref} placeholder={placeholder} disabled={disabled} onChange={handleChange} />
</div>
);
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/speed-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import "./speed-toggle.scss";

interface Props {
fastSimulation: boolean;
disabled: boolean;
onChange: (newValue: boolean) => void;
}

export const SpeedToggle = ({fastSimulation, onChange}: Props) => {
export const SpeedToggle = ({fastSimulation, disabled, onChange}: Props) => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange(e.target.checked);
};
Expand All @@ -27,6 +28,7 @@ export const SpeedToggle = ({fastSimulation, onChange}: Props) => {
title={title}
checked={fastSimulation}
onChange={handleChange}
disabled={disabled}
/>
<div style={getStyle(fastSimulation)} className="fast">Fast</div>
</div>
Expand Down
20 changes: 17 additions & 3 deletions src/components/toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
background-color: #dceff2;
}

&:disabled {
background-color: #ffffff59;
}

&.notImplemented {
cursor: not-allowed;
}

&:hover {
&:hover:not(:disabled) {
background-color: rgba(114, 191, 202, 0.12);
}
}
Expand All @@ -40,7 +44,7 @@
button {
background-color: #177991;

&:hover {
&:hover:not(:disabled) {
background-color: rgba(114, 191, 202, 0.12);

svg {
Expand All @@ -49,6 +53,16 @@
}
}
}
}

&:disabled {
background-color: #ffffff59;

svg {
path {
fill: #177991;
}
}
}
}
}
}
10 changes: 7 additions & 3 deletions src/components/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@ const toolIcons: Record<Tool, any> = {

interface ToolbarButtonProps {
tool: Tool
disabled: boolean
selectedTool: Tool;
onClick: (tool: Tool) => void;
}

interface ToolbarProps {
tools: Tool[]
disabled: boolean
onToolSelected: (tool: Tool) => void;
onReset: () => void;
onReturnToMainMenu: () => void;
onFitView: () => void;
onRecenterView: () => void;
}

export const ToolbarButton = ({tool, selectedTool, onClick}: ToolbarButtonProps) => {
export const ToolbarButton = ({tool, disabled, selectedTool, onClick}: ToolbarButtonProps) => {
const handleClick = () => onClick(tool);
const selected = toggleableTools.includes(tool) && tool === selectedTool;
const notImplemented = notImplementedTools.includes(tool);
Expand All @@ -71,15 +73,15 @@ export const ToolbarButton = ({tool, selectedTool, onClick}: ToolbarButtonProps)
title={title}
onClick={handleClick}
className={clsx({selected, notImplemented})}
disabled={notImplemented}
disabled={disabled || notImplemented}
>
<ToolIcon />
</button>
);
};

export const Toolbar = (props: ToolbarProps) => {
const {tools, onToolSelected, onReset, onReturnToMainMenu, onFitView, onRecenterView} = props;
const {tools, disabled, onToolSelected, onReset, onReturnToMainMenu, onFitView, onRecenterView} = props;
const [selectedTool, setSelectedTool] = useState<Tool>("select");

const handleToolSelected = useCallback((tool: Tool) => {
Expand Down Expand Up @@ -110,6 +112,7 @@ export const Toolbar = (props: ToolbarProps) => {
{topTools.map(tool => (
<ToolbarButton
key={tool}
disabled={disabled}
tool={tool}
selectedTool={selectedTool}
onClick={handleToolSelected}
Expand All @@ -120,6 +123,7 @@ export const Toolbar = (props: ToolbarProps) => {
{bottomTools.map(tool => (
<ToolbarButton
key={tool}
disabled={disabled}
tool={tool}
selectedTool={selectedTool}
onClick={handleToolSelected}
Expand Down
Loading