summaryrefslogtreecommitdiff
path: root/frontend/script.js
blob: 5af0c08190f7573d54906d989d44e3706fa0a2ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
document.addEventListener('DOMContentLoaded', () => {
	const fileInput = document.getElementById('file-input');
	const fileList = document.getElementById('file-list');
	const btn = document.getElementById('doit-btn');
	const cont = document.getElementById('mindmap');
	
	var files;

        fileInput.addEventListener('change', (event) => {
		fileList.innerHTML = "";

		files = event.target.files;

		for (let i = 0; i < files.length; i++) {
			fileList.innerHTML += `<li>${files[i].name}</li>`;
		}
	});

	btn.addEventListener('click', async () => {
		if (files.length == 0) return;

		const formData = new FormData();

		for (let i = 0; i < files.length; i++) {
			formData.append('files', files[i]);
		}

		cont.innerHTML = "Generating...";
		
		const response = await fetch("http://127.0.0.1:9000/yeah", {
			method: "POST",
			body: formData
		})


		const data = await response.json();

		lines = data.map.split('\n')

		cont.innerHTML = "";

		for (let i = 0; i < lines.length; i++) {
			if (lines.length == 0) return;

			let depth = 0;
			for (let j = 0; j < lines[i].length; j++) {
				if (lines[i][j] == ">") {
					depth++;
				} else {break;}
			}
console.log(lines[i].slice(depth, lines[i].length))
			cont.innerHTML += `<div style="display: flex; gap: 1rem;"><span style="opacity: 50%; margin-left: ${(depth - 1) * 2}rem"> ▸ </span><span>${lines[i].slice(depth, lines[i].length)}</span></div>`;
			console.log(cont.innerHTML);
		}
	});
});