tree data structure for the zooms of augment
This commit is contained in:
parent
b4f5abb7e1
commit
df63293977
@ -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<CollapsableEmails> {
|
||||
static bool left = true;
|
||||
static bool right = true;
|
||||
web.EventListener? _listener;
|
||||
List<String> hirarchy = ["h1", "h2", "h3", "h4", "h5", "h6", "p"];
|
||||
List<String> tagsCollected = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -140,6 +143,9 @@ class _CollapsableEmailsState extends State<CollapsableEmails> {
|
||||
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<CollapsableEmails> {
|
||||
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
|
||||
|
@ -127,7 +127,8 @@ class AttachmentInfoList extends Iterable<AttachmentInfo> {
|
||||
AttachmentInfoList(this._attachments);
|
||||
|
||||
factory AttachmentInfoList.fromJsonList(List<Map<String, dynamic>> 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<String, dynamic> json) {
|
||||
return AttachmentResponse(name: json["name"], data: Uint8List.fromList(List<int>.from(json["data"])));
|
||||
return AttachmentResponse(
|
||||
name: json["name"],
|
||||
data: Uint8List.fromList(List<int>.from(json["data"])));
|
||||
}
|
||||
}
|
||||
|
||||
class AugmentTree {
|
||||
List children = [];
|
||||
AugmentTree? node;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user