68d072bProject picker landing page with per-project file systemsJeremy Magland 1import { loadBuiltinTheme, registerBuiltinLanguages } from 'minwebide';
2import { openIde } from './ide';
3import { renderLanding } from './landing';
4import { getProject } from './projects';
6// Routes:
7// #/ project picker (landing page)
8// #/project/<id> the IDE, opened on that project's file system
62f426bminwebide demo app: deploys to GitHub PagesJeremy Magland 9
68d072bProject picker landing page with per-project file systemsJeremy Magland 10async function start(): Promise<void> {
11 const app = document.getElementById('app')!;
62f426bminwebide demo app: deploys to GitHub PagesJeremy Magland 12
68d072bProject picker landing page with per-project file systemsJeremy Magland 13 // one-time global setup: theme + languages are shared by all views
62f426bminwebide demo app: deploys to GitHub PagesJeremy Magland 14 const theme = await loadBuiltinTheme('dark_modern');
15 await registerBuiltinLanguages(theme);
68d072bProject picker landing page with per-project file systemsJeremy Magland 17 let current: { dispose(): void } | undefined;
18 let navigating = false;
20 const route = async () => {
21 if (navigating) {
22 return;
23 }
24 navigating = true;
25 try {
26 current?.dispose();
27 current = undefined;
28 app.textContent = '';
30 const match = location.hash.match(/^#\/project\/([a-z0-9]+)/i);
31 if (match) {
32 const project = getProject(match[1]);
33 if (project) {
34 current = await openIde(app, project, theme);
35 return;
36 }
37 // unknown project id: fall through to the landing page
38 history.replaceState(null, '', '#/');
39 }
40 current = renderLanding(app, theme);
41 } finally {
42 navigating = false;
43 }
44 };
46 window.addEventListener('hashchange', route);
47 await route();