NodeDetailScreen constructor

NodeDetailScreen(
  1. AppContext ctx,
  2. String nodeId
)

Builds the screen for nodeId.

Implementation

NodeDetailScreen(this.ctx, this.nodeId) {
  // Created before the first _render(), which builds the sessions card.
  _sessions = SessionsController(ctx.service, nodeId);
  _body = div(classes: 'stack');
  element = el(
    'div',
    classes: 'stack',
    children: [
      el(
        'div',
        classes: 'toolbar',
        children: [
          button(
            '← Nodes',
            className: 'ghost',
            onClick: () => ctx.router.go('/nodes'),
          ),
          el('h1', text: nodeId, classes: 'grow node-title'),
          button(
            'New shell',
            primary: true,
            onClick: () => ctx.router.go(
              '/nodes/${Uri.encodeComponent(nodeId)}/sessions/new',
            ),
          ),
        ],
      ),
      _body,
    ],
  );

  _sub = ctx.nodes.state.stream.listen((_) => _render());
  _sessionsSub = _sessions.state.stream.listen(_renderSessions);
  // Kick off the session load first so the initial render shows its spinner
  // (refresh() sets the loading state synchronously before awaiting).
  unawaited(_sessions.refresh());
  _render();
  if (ctx.nodes.byId(nodeId) == null) {
    unawaited(ctx.nodes.load());
  }
}