danylokhodus commited on
Commit
208a8d6
·
1 Parent(s): c33213f
Files changed (1) hide show
  1. src/pages/CanvasPage.jsx +95 -12
src/pages/CanvasPage.jsx CHANGED
@@ -1405,6 +1405,7 @@ const TaskListView = ({
1405
  }) => {
1406
  const [addingTagNodeId, setAddingTagNodeId] = useState(null);
1407
  const [inlineTagText, setInlineTagText] = useState('');
 
1408
 
1409
  // 1. Identify subgoals & build dependency structures
1410
  const subgoalEdges = useMemo(() => edges.filter(e => e.sourceHandle?.startsWith('subgoals-source')), [edges]);
@@ -1424,21 +1425,38 @@ const TaskListView = ({
1424
  const normalEdge = normalEdges.find(e => e.target === nodeId);
1425
  if (normalEdge) {
1426
  const predId = normalEdge.source;
1427
-
1428
- // If the predecessor itself is a subgoal target (has an incoming subgoal edge),
1429
- // then that predecessor is the conceptual parent subgoal of this branch!
1430
- const predIsSubgoalTarget = subgoalEdges.some(e => e.target === predId);
1431
- if (predIsSubgoalTarget) {
1432
- return predId;
1433
- }
1434
-
1435
- // Otherwise, recursively trace back the sequence to find the subgoal target that started the branch
1436
  return findParentId(predId, visited);
1437
  }
1438
 
1439
  return null;
1440
  }, [subgoalEdges, normalEdges]);
1441
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1442
  const getSubtasks = useCallback((parentId) => {
1443
  const list = nodes
1444
  .filter(n => n.type === 'sketch' || n.type === 'habit')
@@ -1551,7 +1569,7 @@ const TaskListView = ({
1551
  });
1552
  };
1553
 
1554
- const renderTaskCard = (node, depth = 0) => {
1555
  const subtasks = getSubtasks(node.id).filter(nodeOrDescendantMatches);
1556
  const isExpanded = expandedNodes.has(node.id);
1557
  const hasSubtasks = subtasks.length > 0;
@@ -1578,6 +1596,12 @@ const TaskListView = ({
1578
  <div
1579
  className={`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} ${
1580
  !node.data?.isReached ? 'opacity-65' : ''
 
 
 
 
 
 
1581
  }`}
1582
  >
1583
  <div className="flex items-start gap-3 flex-1 min-w-0">
@@ -1606,6 +1630,16 @@ const TaskListView = ({
1606
 
1607
  <div className="min-w-0 flex-1">
1608
  <div className="flex flex-wrap items-center gap-2">
 
 
 
 
 
 
 
 
 
 
1609
  <span className={`font-display-md text-base text-primary leading-snug break-words ${isDone ? 'line-through opacity-50' : ''}`}>
1610
  {node.data?.label || (node.type === 'habit' ? t('canvas.new_habit', 'Нова звичка') : t('canvas.goal_node', 'Ціль'))}
1611
  </span>
@@ -1788,8 +1822,57 @@ const TaskListView = ({
1788
  </div>
1789
 
1790
  {hasSubtasks && isExpanded && (
1791
- <div className="pl-6 border-l-2 border-dashed border-primary/20 ml-4 space-y-4 pt-1 pb-2">
1792
- {subtasks.map(sub => renderTaskCard(sub, depth + 1))}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1793
  </div>
1794
  )}
1795
  </div>
 
1405
  }) => {
1406
  const [addingTagNodeId, setAddingTagNodeId] = useState(null);
1407
  const [inlineTagText, setInlineTagText] = useState('');
1408
+ const [collapsedBranches, setCollapsedBranches] = useState(new Set());
1409
 
1410
  // 1. Identify subgoals & build dependency structures
1411
  const subgoalEdges = useMemo(() => edges.filter(e => e.sourceHandle?.startsWith('subgoals-source')), [edges]);
 
1425
  const normalEdge = normalEdges.find(e => e.target === nodeId);
1426
  if (normalEdge) {
1427
  const predId = normalEdge.source;
 
 
 
 
 
 
 
 
 
1428
  return findParentId(predId, visited);
1429
  }
1430
 
1431
  return null;
1432
  }, [subgoalEdges, normalEdges]);
1433
 
1434
+ const getBranchNodes = useCallback((subgoalId) => {
1435
+ const branch = [];
1436
+ const visited = new Set();
1437
+
1438
+ const traverse = (nodeId) => {
1439
+ if (visited.has(nodeId)) return;
1440
+ visited.add(nodeId);
1441
+
1442
+ const node = nodes.find(n => n.id === nodeId);
1443
+ if (node && (node.type === 'sketch' || node.type === 'habit')) {
1444
+ branch.push(node);
1445
+ }
1446
+
1447
+ const outgoingEdges = normalEdges.filter(e => e.source === nodeId);
1448
+ const sortedTargets = outgoingEdges
1449
+ .map(e => nodes.find(n => n.id === e.target))
1450
+ .filter(Boolean)
1451
+ .sort((a, b) => (a.position?.y || 0) - (b.position?.y || 0));
1452
+
1453
+ sortedTargets.forEach(t => traverse(t.id));
1454
+ };
1455
+
1456
+ traverse(subgoalId);
1457
+ return branch;
1458
+ }, [nodes, normalEdges]);
1459
+
1460
  const getSubtasks = useCallback((parentId) => {
1461
  const list = nodes
1462
  .filter(n => n.type === 'sketch' || n.type === 'habit')
 
1569
  });
1570
  };
1571
 
1572
+ const renderTaskCard = (node, depth = 0, isSubgoalHead = false, isContinuation = false) => {
1573
  const subtasks = getSubtasks(node.id).filter(nodeOrDescendantMatches);
1574
  const isExpanded = expandedNodes.has(node.id);
1575
  const hasSubtasks = subtasks.length > 0;
 
1596
  <div
1597
  className={`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} ${
1598
  !node.data?.isReached ? 'opacity-65' : ''
1599
+ } ${
1600
+ isSubgoalHead
1601
+ ? 'border-l-[6px] !border-l-yellow-500 border-dashed bg-yellow-500/5 dark:bg-yellow-500/10'
1602
+ : isContinuation
1603
+ ? 'border-l-[6px] !border-l-emerald-500 bg-emerald-500/5 dark:bg-emerald-500/10'
1604
+ : ''
1605
  }`}
1606
  >
1607
  <div className="flex items-start gap-3 flex-1 min-w-0">
 
1630
 
1631
  <div className="min-w-0 flex-1">
1632
  <div className="flex flex-wrap items-center gap-2">
1633
+ {isSubgoalHead && (
1634
+ <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)]">
1635
+ Субгілка (Субціль)
1636
+ </span>
1637
+ )}
1638
+ {isContinuation && (
1639
+ <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)]">
1640
+ Продовження
1641
+ </span>
1642
+ )}
1643
  <span className={`font-display-md text-base text-primary leading-snug break-words ${isDone ? 'line-through opacity-50' : ''}`}>
1644
  {node.data?.label || (node.type === 'habit' ? t('canvas.new_habit', 'Нова звичка') : t('canvas.goal_node', 'Ціль'))}
1645
  </span>
 
1822
  </div>
1823
 
1824
  {hasSubtasks && isExpanded && (
1825
+ <div className="pl-4 ml-2 space-y-6 pt-2 pb-2">
1826
+ {(() => {
1827
+ const directSubgoals = subgoalEdges
1828
+ .filter(e => e.source === node.id)
1829
+ .map(e => nodes.find(n => n.id === e.target))
1830
+ .filter(Boolean)
1831
+ .sort((a, b) => (a.position?.y || 0) - (b.position?.y || 0));
1832
+
1833
+ return directSubgoals.map(subgoal => {
1834
+ const branchNodes = getBranchNodes(subgoal.id).filter(nodeOrDescendantMatches);
1835
+ if (branchNodes.length === 0) return null;
1836
+
1837
+ const isBranchCollapsed = collapsedBranches.has(subgoal.id);
1838
+
1839
+ return (
1840
+ <div key={subgoal.id} className="space-y-4">
1841
+ {/* Branch divider */}
1842
+ <div className="flex items-center gap-2 py-1 select-none">
1843
+ <div className="flex-1 h-0.5 border-t-2 border-dashed border-primary/20" />
1844
+ <button
1845
+ onClick={() => {
1846
+ const newSet = new Set(collapsedBranches);
1847
+ if (newSet.has(subgoal.id)) {
1848
+ newSet.delete(subgoal.id);
1849
+ } else {
1850
+ newSet.add(subgoal.id);
1851
+ }
1852
+ setCollapsedBranches(newSet);
1853
+ }}
1854
+ 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"
1855
+ >
1856
+ <span className="font-mono text-xs font-extrabold tracking-tighter">
1857
+ {isBranchCollapsed ? '----(+)' : '----(-)'}
1858
+ </span>
1859
+ </button>
1860
+ <div className="flex-1 h-0.5 border-t-2 border-dashed border-primary/20" />
1861
+ </div>
1862
+
1863
+ {/* Branch contents */}
1864
+ {!isBranchCollapsed && (
1865
+ <div className="pl-6 border-l-2 border-dashed border-primary/20 ml-4 space-y-4">
1866
+ {branchNodes.map((bNode) => {
1867
+ const isHead = bNode.id === subgoal.id;
1868
+ return renderTaskCard(bNode, depth + 1, isHead, !isHead);
1869
+ })}
1870
+ </div>
1871
+ )}
1872
+ </div>
1873
+ );
1874
+ });
1875
+ })()}
1876
  </div>
1877
  )}
1878
  </div>