Skip to content

Commit 66a66d3

Browse files
committed
wip
1 parent 46bb366 commit 66a66d3

File tree

10 files changed

+271
-65
lines changed

10 files changed

+271
-65
lines changed

webapp/src/index.js

Lines changed: 181 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import App from './App';
5-
import reportWebVitals from './reportWebVitals';
65

7-
// Application initialization timestamp
8-
const startTime = performance.now();
96
// Configure console styling
107
const logStyles = {
118
startup: 'color: #4CAF50; font-weight: bold',
@@ -15,6 +12,185 @@ const logStyles = {
1512
};
1613

1714

15+
// Application initialization timestamp
16+
const startTime = performance.now();
17+
console.log('%c[Chat App] Application initialization started at:', logStyles.info, new Date().toISOString());
18+
19+
// Function to load and execute tab_fallback.js
20+
function loadTabFallback() {
21+
console.log('%c[Chat App] Loading tab fallback functionality...', logStyles.info);
22+
console.log('%c[Chat App] Current DOM state:', logStyles.info, {
23+
tabButtons: document.querySelectorAll('.tab-button').length,
24+
tabContainers: document.querySelectorAll('.tabs-container').length,
25+
timestamp: new Date().toISOString()
26+
});
27+
28+
function updateTabs() {
29+
try {
30+
document.querySelectorAll('.tab-button').forEach(button => {
31+
const tabId = button.getAttribute('data-for-tab');
32+
console.log('%c[Chat App] Adding click listener to tab:', logStyles.info, {
33+
tabId,
34+
buttonElement: button,
35+
containerElement: button.closest('.tabs-container'),
36+
timestamp: new Date().toISOString()
37+
});
38+
button.addEventListener('click', (event) => {
39+
try {
40+
console.log('%c[Chat App] Tab clicked:', logStyles.info, {
41+
tab: button.getAttribute('data-for-tab'),
42+
element: button,
43+
container: button.closest('.tabs-container').id,
44+
timestamp: new Date().toISOString()
45+
});
46+
event.stopPropagation();
47+
const forTab = button.getAttribute('data-for-tab');
48+
const tabsContainerId = button.closest('.tabs-container').id;
49+
console.log('%c[Chat App] Saving tab state:', logStyles.info, {
50+
containerId: tabsContainerId,
51+
selectedTab: forTab,
52+
previousTab: localStorage.getItem(`selectedTab_${tabsContainerId}`),
53+
timestamp: new Date().toISOString()
54+
});
55+
localStorage.setItem(`selectedTab_${tabsContainerId}`, forTab);
56+
let tabsParent = button.closest('.tabs-container');
57+
const activeButtons = Array.from(tabsParent.querySelectorAll('.tab-button.active'))
58+
.map(btn => btn.getAttribute('data-for-tab'));
59+
console.log('%c[Chat App] Currently active buttons:', logStyles.info, activeButtons);
60+
61+
tabsParent.querySelectorAll('.tab-button').forEach(tabButton => {
62+
if (tabButton.closest('.tabs-container') === tabsParent) tabButton.classList.remove('active');
63+
});
64+
button.classList.add('active');
65+
console.log('%c[Chat App] Tab activated:', logStyles.info, {
66+
tab: forTab,
67+
container: tabsContainerId,
68+
timestamp: new Date().toISOString()
69+
});
70+
let selectedContent = null;
71+
tabsParent.querySelectorAll('.tab-content').forEach(content => {
72+
if (content.closest('.tabs-container') === tabsParent) {
73+
if (content.getAttribute('data-tab') === forTab) {
74+
content.classList.add('active');
75+
content.style.display = 'block'; // Ensure the content is displayed
76+
console.log('%c[Chat App] Tab content displayed:', logStyles.info, {
77+
tab: forTab,
78+
content: content.innerHTML.substring(0, 100) + '...',
79+
timestamp: new Date().toISOString()
80+
});
81+
selectedContent = content;
82+
} else {
83+
content.classList.remove('active');
84+
content.style.display = 'none'; // Ensure the content is hidden
85+
console.log('%c[Chat App] Tab content hidden:', logStyles.info, {
86+
tab: content.getAttribute('data-tab'),
87+
timestamp: new Date().toISOString()
88+
});
89+
}
90+
}
91+
});
92+
if (selectedContent !== null) updateNestedTabs(selectedContent);
93+
} catch (error) {
94+
console.error('%c[Chat App] Error in tab click handler:', logStyles.error, {
95+
error: error.message,
96+
stack: error.stack,
97+
tab: button.getAttribute('data-for-tab'),
98+
container: button.closest('.tabs-container')?.id
99+
});
100+
}
101+
});
102+
// Check if the current button should be activated based on localStorage
103+
const savedTab = localStorage.getItem(`selectedTab_${button.closest('.tabs-container').id}`);
104+
console.log('%c[Chat App] Checking saved tab state:', logStyles.info, {
105+
container: button.closest('.tabs-container').id,
106+
savedTab: savedTab,
107+
buttonTab: button.getAttribute('data-for-tab'),
108+
timestamp: new Date().toISOString()
109+
});
110+
if (button.getAttribute('data-for-tab') === savedTab) {
111+
button.dispatchEvent(new Event('click'));
112+
}
113+
});
114+
} catch (error) {
115+
console.error('%c[Chat App] Fatal error in updateTabs:', logStyles.error, {
116+
error: error.message,
117+
stack: error.stack,
118+
timestamp: new Date().toISOString()
119+
});
120+
}
121+
}
122+
123+
function updateNestedTabs(element) {
124+
console.log('%c[Chat App] Updating nested tabs for element:', logStyles.info, element);
125+
element.querySelectorAll('.tabs-container').forEach(tabsContainer => {
126+
try {
127+
console.log('%c[Chat App] Processing nested tab container:', logStyles.info, tabsContainer.id);
128+
let hasActiveButton = false;
129+
tabsContainer.querySelectorAll('.tab-button').forEach(nestedButton => {
130+
if (nestedButton.classList.contains('active')) {
131+
hasActiveButton = true;
132+
console.log('%c[Chat App] Found active nested button:', logStyles.info, nestedButton.getAttribute('data-for-tab'));
133+
}
134+
});
135+
if (!hasActiveButton) {
136+
/* Determine if a tab-content element in this tabs-container has the active class. If so, use its data-tab value to find the matching button and ensure it is marked active */
137+
const activeContent = tabsContainer.querySelector('.tab-content.active');
138+
if (activeContent) {
139+
const activeTab = activeContent.getAttribute('data-tab');
140+
const activeButton = tabsContainer.querySelector(`.tab-button[data-for-tab="${activeTab}"]`);
141+
if (activeButton !== null) {
142+
activeButton.classList.add('active');
143+
console.log('%c[Chat App] Activated nested button:', logStyles.info, activeTab);
144+
}
145+
} else {
146+
/* Add 'active' to the class list of the first button */
147+
const firstButton = tabsContainer.querySelector('.tab-button');
148+
if (firstButton !== null) {
149+
firstButton.classList.add('active');
150+
console.log('%c[Chat App] Activated first nested button:', logStyles.info, firstButton.getAttribute('data-for-tab'));
151+
}
152+
}
153+
}
154+
const savedTab = localStorage.getItem(`selectedTab_${tabsContainer.id}`);
155+
// console.log(`Retrieved saved tab from localStorage: selectedTab_${tabsContainer.id} = ${savedTab}`);
156+
if (savedTab) {
157+
const savedButton = tabsContainer.querySelector(`.tab-button[data-for-tab="${savedTab}"]`);
158+
if (savedButton) {
159+
savedButton.classList.add('active');
160+
const forTab = savedButton.getAttribute('data-for-tab');
161+
const selectedContent = tabsContainer.querySelector(`.tab-content[data-tab="${forTab}"]`);
162+
if (selectedContent) {
163+
selectedContent.classList.add('active');
164+
selectedContent.style.display = 'block';
165+
}
166+
// console.log(`Restored saved tab: ${savedTab}`);
167+
}
168+
}
169+
} catch (e) {
170+
console.error('%c[Chat App] Error updating nested tabs:', logStyles.error, {
171+
error: e.message,
172+
stack: e.stack,
173+
container: tabsContainer.id
174+
});
175+
}
176+
});
177+
}
178+
179+
try {
180+
console.log('%c[Chat App] Initializing tabs...', logStyles.info, {
181+
timestamp: new Date().toISOString(),
182+
documentReady: document.readyState
183+
});
184+
updateTabs();
185+
} catch (error) {
186+
console.error('%c[Chat App] Failed to initialize tabs:', logStyles.error, {
187+
error: error.message,
188+
stack: error.stack,
189+
timestamp: new Date().toISOString()
190+
});
191+
}
192+
}
193+
18194

19195
// Check if we're loading from an archive based on current document length
20196
const isArchive = document.documentElement.outerHTML.length > 60000;
@@ -23,6 +199,7 @@ if (!isArchive) {
23199
console.log('%c[Chat App] Starting application...', logStyles.startup);
24200
} else {
25201
console.log('%c[Chat App] Starting application in archive mode...', logStyles.startup);
202+
loadTabFallback();
26203
}
27204

28205

@@ -56,4 +233,4 @@ if (typeof document !== 'undefined') {
56233
'%c[Chat App] Document is undefined - application may be running in a non-browser environment',
57234
logStyles.warning
58235
);
59-
}
236+
}

webui/src/main/resources/application/asset-manifest.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"files": {
33
"main.css": "/static/css/main.0b4c55b7.css",
4-
"main.js": "/static/js/main.6aedd337.js",
4+
"main.js": "/static/js/main.89ea7cbc.js",
55
"static/js/9017.98ad007d.chunk.js": "/static/js/9017.98ad007d.chunk.js",
66
"static/js/5536.9c75127e.chunk.js": "/static/js/5536.9c75127e.chunk.js",
77
"static/js/7035.2bce51c5.chunk.js": "/static/js/7035.2bce51c5.chunk.js",
@@ -59,7 +59,6 @@
5959
"static/js/5696.3212bab0.chunk.js": "/static/js/5696.3212bab0.chunk.js",
6060
"static/css/7970.f6d5dcec.chunk.css": "/static/css/7970.f6d5dcec.chunk.css",
6161
"static/js/7970.f5940b18.chunk.js": "/static/js/7970.f5940b18.chunk.js",
62-
"static/js/2488.36745428.chunk.js": "/static/js/2488.36745428.chunk.js",
6362
"static/js/2301.d12f4d93.chunk.js": "/static/js/2301.d12f4d93.chunk.js",
6463
"static/js/3955.c351b019.chunk.js": "/static/js/3955.c351b019.chunk.js",
6564
"static/js/2538.5a1c5cfb.chunk.js": "/static/js/2538.5a1c5cfb.chunk.js",
@@ -73,7 +72,7 @@
7372
"static/js/5195.756798f5.chunk.js": "/static/js/5195.756798f5.chunk.js",
7473
"index.html": "/index.html",
7574
"main.0b4c55b7.css.map": "/static/css/main.0b4c55b7.css.map",
76-
"main.6aedd337.js.map": "/static/js/main.6aedd337.js.map",
75+
"main.89ea7cbc.js.map": "/static/js/main.89ea7cbc.js.map",
7776
"9017.98ad007d.chunk.js.map": "/static/js/9017.98ad007d.chunk.js.map",
7877
"5536.9c75127e.chunk.js.map": "/static/js/5536.9c75127e.chunk.js.map",
7978
"7035.2bce51c5.chunk.js.map": "/static/js/7035.2bce51c5.chunk.js.map",
@@ -131,7 +130,6 @@
131130
"5696.3212bab0.chunk.js.map": "/static/js/5696.3212bab0.chunk.js.map",
132131
"7970.f6d5dcec.chunk.css.map": "/static/css/7970.f6d5dcec.chunk.css.map",
133132
"7970.f5940b18.chunk.js.map": "/static/js/7970.f5940b18.chunk.js.map",
134-
"2488.36745428.chunk.js.map": "/static/js/2488.36745428.chunk.js.map",
135133
"7854.819d1079.chunk.js.map": "/static/js/7854.819d1079.chunk.js.map",
136134
"5502.9d720ea3.chunk.js.map": "/static/js/5502.9d720ea3.chunk.js.map",
137135
"62.f94bfd96.chunk.js.map": "/static/js/62.f94bfd96.chunk.js.map",
@@ -141,6 +139,6 @@
141139
},
142140
"entrypoints": [
143141
"static/css/main.0b4c55b7.css",
144-
"static/js/main.6aedd337.js"
142+
"static/js/main.89ea7cbc.js"
145143
]
146144
}

webui/src/main/resources/application/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link rel="apple-touch-icon" href="logo192.png"/>
1010
<link rel="manifest" href="manifest.json"/>
1111
<title>React App</title>
12-
<script defer="defer" src="static/js/main.6aedd337.js"></script>
12+
<script defer="defer" src="static/js/main.89ea7cbc.js"></script>
1313
<link href="static/css/main.0b4c55b7.css" rel="stylesheet">
1414
</head>
1515
<body>

webui/src/main/resources/application/static/css/main.0b4c55b7.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)