diff --git a/src/components/app.tsx b/src/components/app.tsx index 4020805..882d97c 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -98,6 +98,7 @@ export const App = () => { const [initialGraph, setInitialGraph] = useState(); const [fitViewAt, setFitViewAt] = useState(); const [recenterViewAt, setRecenterViewAt] = useState(); + const [resetViewAt, setResetViewAt] = useState(); const onCODAPDataChanged = (values: string[]) => { updateGraph(values); setFitViewAt(Date.now()); @@ -148,6 +149,7 @@ export const App = () => { const [delimiterType, setDelimiterType] = useState( delimiter === "" ? "none" : (delimiter === " " ? "space" : "other")); const [confirmModal, setConfirmModal] = useState(undefined); + const [graphOpacity, setGraphOpacity] = useState(1); const handleDimensionChange = ({width, height}: {width: number, height: number}) => { widthRef.current = width; @@ -532,9 +534,12 @@ export const App = () => { setStartingState(defaultStartingState); setSequenceGroups([]); setFastSimulation(defaultFastSimulation); + setGraphOpacity(0); setGraph(initialGraph ? {...initialGraph} : {nodes: [], edges: []}); + setResetViewAt(Date.now()); setTimeout(() => { setFitViewAt(Date.now()); + setGraphOpacity(1); }, 0); }, onClose: () => setConfirmModal(undefined) @@ -618,6 +623,7 @@ export const App = () => { highlightOutputNodes={highlightOutputNodes} selectedNodeId={selectedNodeId} animating={animating} + graphOpacity={graphOpacity} setGraph={setGraph} setHighlightNode={setHighlightNode} setSelectedNodeId={setSelectedNodeId} @@ -627,6 +633,7 @@ export const App = () => { onRecenterView={handleRecenterView} fitViewAt={fitViewAt} recenterViewAt={recenterViewAt} + resetViewAt={resetViewAt} onDimensions={handleDimensionChange} onClearHighlightOutput={handleClearHighlightOutput} /> @@ -641,6 +648,7 @@ export const App = () => { selectedNodeId={selectedNodeId} animating={animating} graphEmpty={graphEmpty} + graphOpacity={graphOpacity} setSelectedNodeId={setSelectedNodeId} onReset={handleReset} onReturnToMainMenu={handleReturnToMainMenu} diff --git a/src/components/dataset.tsx b/src/components/dataset.tsx index 89cfa4a..ed26a7f 100644 --- a/src/components/dataset.tsx +++ b/src/components/dataset.tsx @@ -16,6 +16,7 @@ interface Props { selectedNodeId?: string; animating: boolean; graphEmpty: boolean; + graphOpacity: number; fitViewAt?: number; recenterViewAt?: number; setSelectedNodeId: (id?: string, skipToggle?: boolean) => void; @@ -29,7 +30,7 @@ interface Props { export const Dataset = (props: Props) => { const {highlightNode, highlightLoopOnNode, highlightEdge, highlightAllNextNodes, highlightOutputNodes, graph, graphEmpty, setSelectedNodeId, selectedNodeId, animating, - fitViewAt, recenterViewAt, + fitViewAt, recenterViewAt, graphOpacity, onReset, onReturnToMainMenu, onFitView, onRecenterView} = props; const [selectedNodeForModal, setSelectedNodeForModal] = useState(undefined); @@ -91,6 +92,7 @@ export const Dataset = (props: Props) => { selectedNodeId={selectedNodeId} onNodeDoubleClick={handleNodeDoubleClicked} animating={animating} + opacity={graphOpacity} allowDragging={true && !animating} autoArrange={true} setSelectedNodeId={setSelectedNodeId} diff --git a/src/components/drawing.tsx b/src/components/drawing.tsx index 28fad2e..39fac0d 100644 --- a/src/components/drawing.tsx +++ b/src/components/drawing.tsx @@ -23,8 +23,10 @@ interface Props { graph: GraphData; selectedNodeId?: string; animating: boolean; + graphOpacity: number; fitViewAt?: number; recenterViewAt?: number; + resetViewAt?: number; setGraph: React.Dispatch>; setHighlightNode: React.Dispatch> setSelectedNodeId: (id?: string, skipToggle?: boolean) => void; @@ -42,7 +44,7 @@ const removePunctuationRegex = /["(){}[\]_+=|\\/><]/g; export const Drawing = (props: Props) => { const {highlightNode, highlightLoopOnNode, highlightEdge, highlightAllNextNodes, highlightOutputNodes, graph, setGraph, setHighlightNode, setSelectedNodeId: _setSelectedNodeId, - fitViewAt, recenterViewAt, onClearHighlightOutput, + fitViewAt, recenterViewAt, onClearHighlightOutput, graphOpacity, resetViewAt, selectedNodeId, animating, onReset, onReturnToMainMenu, onFitView, onRecenterView} = props; const [drawingMode, setDrawingMode] = useState("select"); const [firstEdgeNode, setFirstEdgeNode] = useState(undefined); @@ -343,6 +345,7 @@ export const Drawing = (props: Props) => { highlightOutputNodes={highlightOutputNodes} highlightLoopOnNode={highlightLoopOnNode} allowDragging={drawingMode === "select"} + opacity={graphOpacity} autoArrange={autoArrange} rubberBand={rubberBand} selectedNodeId={selectedNodeId} @@ -372,6 +375,7 @@ export const Drawing = (props: Props) => { visible={drawingMode === "addText"} width={addTextWidth} disabled={animating} + resetViewAt={resetViewAt} onChange={handleTextChange} /> diff --git a/src/components/drawing/add-text.tsx b/src/components/drawing/add-text.tsx index e1367fa..b079ed0 100644 --- a/src/components/drawing/add-text.tsx +++ b/src/components/drawing/add-text.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef } from "react"; +import React, { forwardRef, useEffect, useState } from "react"; import { clsx } from "clsx"; import "./add-text.scss"; @@ -7,20 +7,31 @@ interface Props { disabled: boolean; visible: boolean; width: number; + resetViewAt?: number; onChange: (newText: string) => void } // 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(({disabled, visible, width, onChange}: Props, ref) => { +export const AddText = forwardRef((props: Props, ref) => { + const {disabled, visible, width, resetViewAt, onChange} = props; + const [text, setText] = useState(""); + + // listen for reset requests + useEffect(() => { + setText(""); + }, [resetViewAt]); + const handleChange = (e: React.ChangeEvent) => { - onChange(e.currentTarget.value.trim()); + const newText = e.currentTarget.value; + setText(newText); + onChange(newText.trim()); }; return (
-