[EverSteem] Updates - Tree Structure

in Steem Dev3 months ago

I will share some updates of EverSteem with you.

  • I changed the app image
  • I have been implementing a tree structure to manage articles

Tree Structure

I have been using Obsidian to manage my notes, which is a great tool.

So I want to implement a similar tree structure for EverSteem.


There is a context menu to do the followings:

  • create a new folder
  • create a new note
  • rename
  • delete



The tree also supports drag and drop of a node.

The tree node class is like this:

class TreeNode {
  static int _nextId = -1; 

  TreeNode({
    required String title,
    // required this.id,
    this.isFolder = false,
    Iterable<TreeNode>? children,
  })  : id = _nextId++,
        _title = title,
        _children = <TreeNode>[] {
    if (children == null) return;

    for (final TreeNode child in children) {
      child._parent = this;
      _children.add(child);
    }
  }

  String _title;
  final int id;
  final bool isFolder;
  final List<TreeNode> _children;

  String get title => _title;

  Iterable<TreeNode> get children => _children;
  bool get hasChildren => _children.isNotEmpty;
  bool get isLeaf => _children.isEmpty;
  // bool get isLeaf => !isFolder || !hasChildren;

  TreeNode? get parent => _parent;
  TreeNode? _parent;

  int get index => _parent?._children.indexOf(this) ?? -1;

  void updateTitle(String title) {
    _title = title;
  }

  void insertChild(int index, TreeNode node) {
    // Adjust the index if necessary when dropping a node at the same parent
    if (node._parent == this && node.index < index) {
      index--;
    }

    // Ensure the node is removed from its previous parent and update it
    node
      .._parent?._children.remove(node)
      .._parent = this;

    _children.insert(index, node);
  }

  void addChild(TreeNode node) {
    node._parent = this;
    _children.add(node);
  }

  void remove() {
    _parent?._children.remove(this);
    _parent = null;
  }

  List<TreeNode> removeWithDescendants() {
    List<TreeNode> removedNodes = [];

    for (final child in List.from(_children)) {
      removedNodes.addAll(child.removeWithDescendants());
    }
    remove();
    removedNodes.add(this);
    return removedNodes; 
  }
}

The content of a note will be managed in a separate class.

The next implementation will be storing tree and contents in offline storage.

cc.
@pennsif
@steemcurator01

Posted through the ECblog app (https://blog.etain.club)

Sort:  


Write Once, reward forever via EverSteem app


Write Once, reward forever via EverSteem app


Write Once, reward forever via EverSteem app

This post has been featured in the latest edition of Steem News...

Greetings, traveler!
I've been using obsidian for some time now, and I do agree it is incredible to use... I hope it adds well to the EverSteem application; which I recently saw mentioned by @remlaps and I adored the idea! I hope to see more about it for the next weeks. Cheers✨

 2 months ago 

Thank you for your interest.
I have been developing this app intensively!

You can see the result soon!