MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / App

Function App

dashboard/shell/src/main.jsx:195–562  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193// ---------------------------------------------------------------------------
194
195function App() {
196 const [plugins, setPlugins] = useState([]);
197 const [capabilities, setCapabilities] = useState(null);
198 const [projects, setProjects] = useState([]);
199 const [selectedProjectId, setSelectedProjectId] = useState("");
200 const [projectRevision, setProjectRevision] = useState(0);
201 const [active, setActive] = useState("");
202 // Tabs that have been activated at least once; their panels stay mounted
203 // (hidden) afterwards so in-progress exploration survives tab switches.
204 const [visited, setVisited] = useState(() => new Set());
205 const [loadError, setLoadError] = useState("");
206 const [connState, setConnState] = useState("connecting"); // "connecting" | "ok" | "error"
207 const [lastRefresh, setLastRefresh] = useState(null);
208 const [theme, setTheme] = useState(getInitialTheme);
209 const pluginsRef = useRef([]);
210 useRegistryVersion();
211
212 /** Single entry point for tab changes; keeps the URL in sync. */
213 const selectTab = useCallback((name, { push = true, writeUrl = true } = {}) => {
214 setActive(name);
215 setVisited((prev) => {
216 if (prev.has(name)) return prev;
217 const next = new Set(prev);
218 next.add(name);
219 return next;
220 });
221 if (writeUrl) writeTabToUrl(name, { push });
222 }, []);
223
224 // Browser back/forward: restore the tab encoded in the URL. History entries
225 // without a (known) tab — e.g. ones created before this app pushed any state
226 // — fall back to the first plugin so Back never leaves the URL and UI
227 // disagreeing about the active tab.
228 useEffect(() => {
229 function onPopState() {
230 const name = tabFromUrl();
231 const list = pluginsRef.current;
232 const target = list.some((p) => p.name === name) ? name : list[0]?.name;
233 if (target) selectTab(target, { writeUrl: false });
234 }
235 window.addEventListener("popstate", onPopState);
236 return () => window.removeEventListener("popstate", onPopState);
237 }, [selectTab]);
238
239 // Keep ref in sync so keyboard handler always sees current plugins.
240 useEffect(() => {
241 pluginsRef.current = plugins;
242 }, [plugins]);
243
244 // Apply theme to <html>. Note: we do NOT persist here. Writing localStorage
245 // on mount would pin the OS-derived theme and stop following
246 // prefers-color-scheme; persistence happens only on explicit toggle below.
247 useEffect(() => {
248 applyTheme(theme);
249 }, [theme]);
250
251 const toggleTheme = useCallback(() => {
252 setTheme((t) => {

Callers

nothing calls this directly

Calls 15

getSelectedProjectIdFunction · 0.90
fetchJSONFunction · 0.90
useStateFunction · 0.85
writeTabToUrlFunction · 0.85
useEffectFunction · 0.85
applyThemeFunction · 0.85
tabFromUrlFunction · 0.85
injectPluginAssetsFunction · 0.85
basenameFunction · 0.85
useRegistryVersionFunction · 0.70
projectLabelFunction · 0.70

Tested by

no test coverage detected