Flattened the sidebar tree

This commit is contained in:
Gregory Schier
2025-10-17 15:07:02 -07:00
parent 6e9b1db196
commit c34ea20406
14 changed files with 418 additions and 370 deletions

View File

@@ -2,10 +2,11 @@ import type { DragMoveEvent } from '@dnd-kit/core';
import { jotaiStore } from '../../../lib/jotai';
import { selectedIdsFamily } from './atoms';
export interface TreeNode<T extends { id: string }> {
export interface TreeNode<T extends { id: string } > {
children?: TreeNode<T>[];
item: T;
parent: TreeNode<T> | null;
depth: number;
}
export interface SelectableTreeNode<T extends { id: string }> {
@@ -41,9 +42,10 @@ export function equalSubtree<T extends { id: string }>(
}
export function hasAncestor<T extends { id: string }>(node: TreeNode<T>, ancestorId: string) {
// Check parents recursively
if (node.parent == null) return false;
if (node.parent.item.id === ancestorId) return true;
// Check parents recursively
return hasAncestor(node.parent, ancestorId);
}