63 lines
1.5 KiB
JavaScript
Raw Normal View History

2025-10-17 14:46:44 +02:00
import { h, render, Fragment } from 'preact';
2025-10-30 15:00:06 +01:00
import Router from './components/Router.js';
import HealthPill from './components/HealthPill.js';
2025-10-17 14:46:44 +02:00
2025-10-30 15:00:06 +01:00
import HomePage from './pages/Home.js';
import BlockDetailPage from './pages/BlockDetail.js';
import TransactionDetailPage from './pages/TransactionDetail.js';
2025-10-17 14:46:44 +02:00
const ROOT = document.getElementById('app');
function LoadingScreen() {
return h('main', { class: 'wrap' }, h('p', null, 'Loading...'));
}
function AppShell(props) {
return h(
Fragment,
null,
h('header', null, h('h1', null, 'Nomos Block Explorer'), h(HealthPill, null)),
props.children,
);
}
const ROUTES = [
{
name: 'home',
re: /^\/$/,
view: () => h(AppShell, null, h(HomePage, null)),
},
{
name: 'blockDetail',
2025-10-20 15:42:12 +02:00
re: /^\/blocks\/([^/]+)$/,
view: ({ parameters }) => {
return h(AppShell, null, h(BlockDetailPage, { parameters }));
},
2025-10-17 14:46:44 +02:00
},
{
name: 'transactionDetail',
2025-10-20 15:42:12 +02:00
re: /^\/transactions\/([^/]+)$/,
view: ({ parameters }) => h(AppShell, null, h(TransactionDetailPage, { parameters })),
2025-10-17 14:46:44 +02:00
},
];
function AppRouter() {
2025-10-20 15:42:12 +02:00
const wired = ROUTES.map((route) => ({
re: route.re,
view: route.view,
2025-10-17 14:46:44 +02:00
}));
return h(Router, { routes: wired });
}
try {
if (ROOT) {
render(h(LoadingScreen, null), ROOT);
render(h(AppRouter, null), ROOT);
} else {
console.error('Mount element #app not found.');
}
} catch (err) {
console.error('UI Error', err);
}