Computed flow layout, and mobile written into the design
The canvas lays itself out: a layered graph, left to right on a desktop and top to bottom on a phone, with room reserved for the value each edge carries. Nodes cannot be dragged and `NodeDef.position` is gone from the document — a graph nobody can arrange is one worth keeping small, which is what keeps flows atomic. Endpoints join the same layout, so their lanes and the localStorage that remembered where they were dragged go too. Mobile, per the new Responsive section of DESIGN-GUIDELINES.md: the dock caps its width and wraps instead of running off the screen, the dashboard stacks into one column rather than shrinking a wall panel to a fifth of its size, and Home stops widening its grid track past the viewport. A Playwright project at a phone's width fails the build when a screen no longer fits. Along the way: publish is the checkmark that was already there rather than a button that appears and disappears, with discard beside it on both the flow and the dashboard; the brain reveals a neuron's name on the first tap; and the port sparklines get room to breathe.
This commit is contained in:
@@ -20,9 +20,10 @@ import {
|
||||
type SimulationNodeDatum,
|
||||
} from "d3-force"
|
||||
import { motion } from "motion/react"
|
||||
import { useEffect, useMemo } from "react"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
|
||||
import type { BrainGraph } from "@/client"
|
||||
import { useIsMobile } from "@/hooks/useMobile"
|
||||
import { scaleIn } from "@/lib/motion"
|
||||
import { BrainEdge, type BrainEdgeData } from "./BrainEdge"
|
||||
import { BrainNode, type BrainNodeData } from "./BrainNode"
|
||||
@@ -162,6 +163,23 @@ function BrainCanvas() {
|
||||
[data],
|
||||
)
|
||||
|
||||
// A name is revealed on hover, which a finger does not have. On a phone the
|
||||
// first tap says which neuron this is and the second follows it — kept out
|
||||
// of the layout memo so revealing one does not re-run the simulation.
|
||||
const isMobile = useIsMobile()
|
||||
const [revealed, setRevealed] = useState<string | null>(null)
|
||||
const shown = useMemo(
|
||||
() =>
|
||||
revealed
|
||||
? nodes.map((node) =>
|
||||
node.id === revealed
|
||||
? { ...node, data: { ...node.data, revealed: true } }
|
||||
: node,
|
||||
)
|
||||
: nodes,
|
||||
[nodes, revealed],
|
||||
)
|
||||
|
||||
// A rebuild lays the whole graph out afresh, so the viewport someone was
|
||||
// looking through no longer frames anything. Only when the set of neurons
|
||||
// actually changed: a value arriving must not move the canvas.
|
||||
@@ -186,7 +204,7 @@ function BrainCanvas() {
|
||||
className="h-full w-full"
|
||||
>
|
||||
<ReactFlow
|
||||
nodes={nodes}
|
||||
nodes={shown}
|
||||
edges={edges}
|
||||
nodeTypes={nodeTypes}
|
||||
edgeTypes={edgeTypes}
|
||||
@@ -206,10 +224,15 @@ function BrainCanvas() {
|
||||
panOnDrag={false}
|
||||
preventScrolling={false}
|
||||
onNodeClick={(_event, node) => {
|
||||
if (isMobile && revealed !== node.id) {
|
||||
setRevealed(node.id)
|
||||
return
|
||||
}
|
||||
const [flow] = (node.data as BrainNodeData).flows
|
||||
if (flow)
|
||||
navigate({ to: "/flows/$flowName", params: { flowName: flow } })
|
||||
}}
|
||||
onPaneClick={() => setRevealed(null)}
|
||||
className="brain-flat h-full w-full"
|
||||
>
|
||||
{/* The same dot grid the editor's canvas uses, quieter and masked back
|
||||
|
||||
Reference in New Issue
Block a user