Spaces:
Running
Running
Commit ·
208a8d6
1
Parent(s): c33213f
fix3
Browse files1404 unmodified lines14051406140714081409141013 unmodified lines142414251426142714281429143014311432143314341435143614371438143914401441144214431444106 unmodified lines155115521553155415551556155720 unmodified lines15781579158015811582158322 unmodified lines160616071608160916101611176 unmodified lines178817891790179117921793179417951404 unmodified lines}) => {const [addingTagNodeId, setAddingTagNodeId] = useState(null);const [inlineTagText, setInlineTagText] = useState('');// 1. Identify subgoals & build dependency structuresconst subgoalEdges = useMemo(() => edges.filter(e => e.sourceHandle?.startsWith('subgoals-source')), [edges]);13 unmodified linesconst normalEdge = normalEdges.find(e => e.target === nodeId);if (normalEdge) {const predId = normalEdge.source;// If the predecessor itself is a subgoal target (has an incoming subgoal edge),// then that predecessor is the conceptual parent subgoal of this branch!const predIsSubgoalTarget = subgoalEdges.some(e => e.target === predId);if (predIsSubgoalTarget) {return predId;}// Otherwise, recursively trace back the sequence to find the subgoal target that started the branchreturn findParentId(predId, visited);}return null;}, [subgoalEdges, normalEdges]);const getSubtasks = useCallback((parentId) => {const list = nodes.filter(n => n.type === 'sketch' || n.type === 'habit')106 unmodified lines});};const renderTaskCard = (node, depth = 0) => {const subtasks = getSubtasks(node.id).filter(nodeOrDescendantMatches);const isExpanded = expandedNodes.has(node.id);const hasSubtasks = subtasks.length > 0;20 unmodified lines<divclassName={`p-4 border-2 rounded-2xl flex flex-col md:flex-row md:items-center justify-between gap-4 transition-all shadow-[3px_3px_0px_0px_var(--color-primary)] hover:shadow-[5px_5px_0px_0px_var(--color-primary)] ${cardBg} ${!node.data?.isReached ? 'opacity-65' : ''}`}><div className="flex items-start gap-3 flex-1 min-w-0">22 unmodified lines<div className="min-w-0 flex-1"><div className="flex flex-wrap items-center gap-2"><span className={`font-display-md text-base text-primary leading-snug break-words ${isDone ? 'line-through opacity-50' : ''}`}>{node.data?.label || (node.type === 'habit' ? t('canvas.new_habit', 'Нова звичка') : t('canvas.goal_node', 'Ціль'))}</span>176 unmodified lines</div>{hasSubtasks && isExpanded && (<div className="pl-6 border-l-2 border-dashed border-primary/20 ml-4 space-y-4 pt-1 pb-2">{subtasks.map(sub => renderTaskCard(sub, depth + 1))}</div>)}</div>1404 unmodified lines140514061407140814091410141113 unmodified lines14251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462106 unmodified lines156915701571157215731574157520 unmodified lines15961597159815991600160116021603160416051606160722 unmodified lines1630163116321633163416351636163716381639164016411642164316441645176 unmodified lines1822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781404 unmodified lines}) => {const [addingTagNodeId, setAddingTagNodeId] = useState(null);const [inlineTagText, setInlineTagText] = useState('');const [collapsedBranches, setCollapsedBranches] = useState(new Set());// 1. Identify subgoals & build dependency structuresconst subgoalEdges = useMemo(() => edges.filter(e => e.sourceHandle?.startsWith('subgoals-source')), [edges]);13 unmodified linesconst normalEdge = normalEdges.find(e => e.target === nodeId);if (normalEdge) {const predId = normalEdge.source;return findParentId(predId, visited);}return null;}, [subgoalEdges, normalEdges]);const getBranchNodes = useCallback((subgoalId) => {const branch = [];const visited = new Set();const traverse = (nodeId) => {if (visited.has(nodeId)) return;visited.add(nodeId);const node = nodes.find(n => n.id === nodeId);if (node && (node.type === 'sketch' || node.type === 'habit')) {branch.push(node);}const outgoingEdges = normalEdges.filter(e => e.source === nodeId);const sortedTargets = outgoingEdges.map(e => nodes.find(n => n.id === e.target)).filter(Boolean).sort((a, b) => (a.position?.y || 0) - (b.position?.y || 0));sortedTargets.forEach(t => traverse(t.id));};traverse(subgoalId);return branch;}, [nodes, normalEdges]);const getSubtasks = useCallback((parentId) => {const list = nodes.filter(n => n.type === 'sketch' || n.type === 'habit')106 unmodified lines});};const renderTaskCard = (node, depth = 0, isSubgoalHead = false, isContinuation = false) => {const subtasks = getSubtasks(node.id).filter(nodeOrDescendantMatches);const isExpanded = expandedNodes.has(node.id);const hasSubtasks = subtasks.length > 0;20 unmodified lines<divclassName={`p-4 border-2 rounded-2xl flex flex-col md:flex-row md:items-center justify-between gap-4 transition-all shadow-[3px_3px_0px_0px_var(--color-primary)] hover:shadow-[5px_5px_0px_0px_var(--color-primary)] ${cardBg} ${!node.data?.isReached ? 'opacity-65' : ''} ${isSubgoalHead? 'border-l-[6px] !border-l-yellow-500 border-dashed bg-yellow-500/5 dark:bg-yellow-500/10': isContinuation? 'border-l-[6px] !border-l-emerald-500 bg-emerald-500/5 dark:bg-emerald-500/10': ''}`}><div className="flex items-start gap-3 flex-1 min-w-0">22 unmodified lines<div className="min-w-0 flex-1"><div className="flex flex-wrap items-center gap-2">{isSubgoalHead && (<span className="text-[8px] font-extrabold uppercase px-1.5 py-0.5 rounded border border-yellow-500 bg-yellow-500/15 text-yellow-600 dark:text-yellow-400 animate-pulse tracking-wider shadow-[0.5px_0.5px_0px_0px_rgba(0,0,0,0.05)]">Субгілка (Субціль)</span>)}{isContinuation && (<span className="text-[8px] font-extrabold uppercase px-1.5 py-0.5 rounded border border-emerald-500 bg-emerald-500/15 text-emerald-600 dark:text-emerald-400 tracking-wider shadow-[0.5px_0.5px_0px_0px_rgba(0,0,0,0.05)]">Продовження</span>)}<span className={`font-display-md text-base text-primary leading-snug break-words ${isDone ? 'line-through opacity-50' : ''}`}>{node.data?.label || (node.type === 'habit' ? t('canvas.new_habit', 'Нова звичка') : t('canvas.goal_node', 'Ціль'))}</span>176 unmodified lines</div>{hasSubtasks && isExpanded && (<div className="pl-4 ml-2 space-y-6 pt-2 pb-2">{(() => {const directSubgoals = subgoalEdges.filter(e => e.source === node.id).map(e => nodes.find(n => n.id === e.target)).filter(Boolean).sort((a, b) => (a.position?.y || 0) - (b.position?.y || 0));return directSubgoals.map(subgoal => {const branchNodes = getBranchNodes(subgoal.id).filter(nodeOrDescendantMatches);if (branchNodes.length === 0) return null;const isBranchCollapsed = collapsedBranches.has(subgoal.id);return (<div key={subgoal.id} className="space-y-4">{/* Branch divider */}<div className="flex items-center gap-2 py-1 select-none"><div className="flex-1 h-0.5 border-t-2 border-dashed border-primary/20" /><buttononClick={() => {const newSet = new Set(collapsedBranches);if (newSet.has(subgoal.id)) {newSet.delete(subgoal.id);} else {newSet.add(subgoal.id);}setCollapsedBranches(newSet);}}className="px-4 py-1 border-2 border-primary rounded-full bg-surface-container-lowest text-primary text-[10px] font-extrabold flex items-center gap-2 shadow-[2px_2px_0px_0px_var(--color-primary)] active:translate-y-0.5 active:shadow-[1px_1px_0px_0px_var(--color-primary)] cursor-pointer hover:bg-secondary/10"><span className="font-mono text-xs font-extrabold tracking-tighter">{isBranchCollapsed ? '----(+)' : '----(-)'}</span></button><div className="flex-1 h-0.5 border-t-2 border-dashed border-primary/20" /></div>{/* Branch contents */}{!isBranchCollapsed && (<div className="pl-6 border-l-2 border-dashed border-primary/20 ml-4 space-y-4">{branchNodes.map((bNode) => {const isHead = bNode.id === subgoal.id;return renderTaskCard(bNode, depth + 1, isHead, !isHead);})}</div>)}</div>);});})()}</div>)}</div>
src/pages/CanvasPage.jsx+95-12