From df6329397741a5d7e229c9ff9b1909ef2e729fe6 Mon Sep 17 00:00:00 2001 From: juan Date: Tue, 27 May 2025 23:38:37 -0400 Subject: [PATCH] tree data structure for the zooms of augment --- lib/collapsableEmailsWeb.dart | 60 +++++++++++++++++++++++++++++++++++ lib/structs.dart | 12 +++++-- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/lib/collapsableEmailsWeb.dart b/lib/collapsableEmailsWeb.dart index bb7e825..966a10e 100644 --- a/lib/collapsableEmailsWeb.dart +++ b/lib/collapsableEmailsWeb.dart @@ -1,4 +1,5 @@ import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; import 'package:web/web.dart' as web; import 'package:flutter/material.dart'; import 'dart:ui_web' as ui; @@ -31,6 +32,8 @@ class _CollapsableEmailsState extends State { static bool left = true; static bool right = true; web.EventListener? _listener; + List hirarchy = ["h1", "h2", "h3", "h4", "h5", "h6", "p"]; + List tagsCollected = []; @override void initState() { @@ -140,6 +143,9 @@ class _CollapsableEmailsState extends State { final currentElement = purpleNums.item(i) as web.HTMLElement; currentElement.style.opacity = '0.0'; } + } else if (keyEvent.key == 'w') { + print("you pressed 'w'"); + getTopLevel(); } } @@ -152,6 +158,60 @@ class _CollapsableEmailsState extends State { web.window.document.addEventListener('keydown', _listener!); } + void getTopLevel() { + print("started top"); + int highest = 0; + AugmentTree zoomTreeRoot = AugmentTree(); + // zoomTreeRoot.data = emailsHTML[0]; // whole thing + + while (highest < hirarchy.length - 1) { + var highestElement = web.document.querySelectorAll(hirarchy[highest]); + print("nodelist $highestElement"); + + if (highestElement.isNull || highestElement.length == 0) { + //from h1, h2, h3, ..., p. + highest += 1; + print(hirarchy[highest]); + } else { + AugmentTree newLevel = AugmentTree(); // list of children of each level + for (int i = 0; i < highestElement.length; i++) { + print(highestElement.item(i)?.textContent); + + tagsCollected + .add(highestElement.item(i)?.textContent ?? "nameless subtitle"); + newLevel.children + .add(highestElement.item(i)?.textContent ?? "nameless subtitle"); + } + // traverse to last node and add new level to it + // next + if (zoomTreeRoot.node == null) { + zoomTreeRoot.node = newLevel; + } else { + AugmentTree temp = zoomTreeRoot; + while (true) { + //get to the last and assign node = last node + if (temp.node != null) { + temp = temp.node!; + } else { + temp.node = newLevel; + break; + } + } + } + + highest += 1; + } + } + print("out safely"); + print(tagsCollected); //instead of a list make a tree + print(zoomTreeRoot.children); + print(zoomTreeRoot.node?.children); + print(zoomTreeRoot.node?.node?.children); + print(zoomTreeRoot.node?.node?.node?.children); + + + } + @override Widget build(BuildContext context) { return _isLoaded diff --git a/lib/structs.dart b/lib/structs.dart index c7e9da4..4672792 100644 --- a/lib/structs.dart +++ b/lib/structs.dart @@ -127,7 +127,8 @@ class AttachmentInfoList extends Iterable { AttachmentInfoList(this._attachments); factory AttachmentInfoList.fromJsonList(List> jsonList) { - return AttachmentInfoList(jsonList.map((json) => AttachmentInfo.fromJson(json)).toList()); + return AttachmentInfoList( + jsonList.map((json) => AttachmentInfo.fromJson(json)).toList()); } @override @@ -143,6 +144,13 @@ class AttachmentResponse { AttachmentResponse({required this.name, required this.data}); factory AttachmentResponse.fromJson(Map json) { - return AttachmentResponse(name: json["name"], data: Uint8List.fromList(List.from(json["data"]))); + return AttachmentResponse( + name: json["name"], + data: Uint8List.fromList(List.from(json["data"]))); } } + +class AugmentTree { + List children = []; + AugmentTree? node; +}