Pointf5ive commited on
Commit
26d3c0e
·
1 Parent(s): c0388f3

fix: wire topbar dashboard/codex/smoke chips to real tabs

Browse files
Files changed (1) hide show
  1. app.py +42 -16
app.py CHANGED
@@ -1110,34 +1110,60 @@ TOTEM_CSS = """
1110
  HEAD = """
1111
  <script>
1112
  (() => {
1113
- const switchToCodexTab = () => {
1114
  const tabs = Array.from(document.querySelectorAll('[role="tab"]'));
1115
  if (!tabs.length) return false;
1116
- const target = tabs.find((tab) => /codex extractor/i.test((tab.textContent || "").trim()));
1117
  if (target) {
1118
  target.click();
1119
  return true;
1120
  }
 
 
 
 
 
 
 
 
1121
  if (tabs.length > 1) {
1122
  tabs[1].click();
1123
  return true;
1124
  }
1125
  return false;
1126
  };
 
 
 
 
 
 
 
 
 
 
1127
 
1128
  const bindSidebarCodexLinks = () => {
1129
- document.querySelectorAll('.js-open-codex').forEach((el) => {
1130
- if (el.dataset.boundCodexNav === "1") return;
1131
- el.dataset.boundCodexNav = "1";
1132
- el.addEventListener('click', (e) => {
1133
- e.preventDefault();
1134
- switchToCodexTab();
1135
- });
1136
- el.addEventListener('keydown', (e) => {
1137
- if (e.key === 'Enter' || e.key === ' ') {
 
 
1138
  e.preventDefault();
1139
- switchToCodexTab();
1140
- }
 
 
 
 
 
 
1141
  });
1142
  });
1143
  };
@@ -1382,9 +1408,9 @@ def render_topbar(state: dict) -> str:
1382
  return f"""
1383
  <section class="totem-topbar">
1384
  <div>
1385
- <span class="totem-chip active">Dashboard</span>
1386
- <span class="totem-chip">Codex Extractor</span>
1387
- <span class="totem-chip">Smoke Signal</span>
1388
  </div>
1389
  <div class="totem-search">Search projects, workbooks, blocks...</div>
1390
  <div class="totem-workspace">
 
1110
  HEAD = """
1111
  <script>
1112
  (() => {
1113
+ const switchToTabByMatcher = (matcher) => {
1114
  const tabs = Array.from(document.querySelectorAll('[role="tab"]'));
1115
  if (!tabs.length) return false;
1116
+ const target = tabs.find((tab, index) => matcher((tab.textContent || "").trim(), index));
1117
  if (target) {
1118
  target.click();
1119
  return true;
1120
  }
1121
+ return false;
1122
+ };
1123
+
1124
+ const switchToDashboardTab = () => switchToTabByMatcher((label) => /dashboard/i.test(label));
1125
+ const switchToCodexTab = () => {
1126
+ const byName = switchToTabByMatcher((label) => /codex extractor/i.test(label));
1127
+ if (byName) return true;
1128
+ const tabs = Array.from(document.querySelectorAll('[role="tab"]'));
1129
  if (tabs.length > 1) {
1130
  tabs[1].click();
1131
  return true;
1132
  }
1133
  return false;
1134
  };
1135
+ const switchToSmokeSignalTab = () => {
1136
+ const byName = switchToTabByMatcher((label) => /smoke signal/i.test(label));
1137
+ if (byName) return true;
1138
+ const tabs = Array.from(document.querySelectorAll('[role="tab"]'));
1139
+ if (tabs.length > 2) {
1140
+ tabs[2].click();
1141
+ return true;
1142
+ }
1143
+ return false;
1144
+ };
1145
 
1146
  const bindSidebarCodexLinks = () => {
1147
+ const bindings = [
1148
+ { selector: '.js-open-dashboard', handler: switchToDashboardTab },
1149
+ { selector: '.js-open-codex', handler: switchToCodexTab },
1150
+ { selector: '.js-open-smoke-signal', handler: switchToSmokeSignalTab },
1151
+ ];
1152
+
1153
+ bindings.forEach(({ selector, handler }) => {
1154
+ document.querySelectorAll(selector).forEach((el) => {
1155
+ if (el.dataset.boundTotemNav === "1") return;
1156
+ el.dataset.boundTotemNav = "1";
1157
+ el.addEventListener('click', (e) => {
1158
  e.preventDefault();
1159
+ handler();
1160
+ });
1161
+ el.addEventListener('keydown', (e) => {
1162
+ if (e.key === 'Enter' || e.key === ' ') {
1163
+ e.preventDefault();
1164
+ handler();
1165
+ }
1166
+ });
1167
  });
1168
  });
1169
  };
 
1408
  return f"""
1409
  <section class="totem-topbar">
1410
  <div>
1411
+ <span class="totem-chip active js-open-dashboard" role="button" tabindex="0" aria-label="Open Dashboard tab">Dashboard</span>
1412
+ <span class="totem-chip js-open-codex" role="button" tabindex="0" aria-label="Open Codex Extractor tab">Codex Extractor</span>
1413
+ <span class="totem-chip js-open-smoke-signal" role="button" tabindex="0" aria-label="Open Smoke Signal tab">Smoke Signal</span>
1414
  </div>
1415
  <div class="totem-search">Search projects, workbooks, blocks...</div>
1416
  <div class="totem-workspace">