• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import * as m from 'mithril';
16
17import {Actions} from '../common/actions';
18
19import {CookieConsent} from './cookie_consent';
20import {globals} from './globals';
21import {Sidebar} from './sidebar';
22import {Topbar} from './topbar';
23
24function renderPermalink(): m.Children {
25  const permalink = globals.state.permalink;
26  if (!permalink.requestId || !permalink.hash) return null;
27  const url = `${self.location.origin}/#!/?s=${permalink.hash}`;
28
29  return m('.alert-permalink', [
30    m('div', 'Permalink: ', m(`a[href=${url}]`, url)),
31    m('button',
32      {
33        onclick: () => globals.dispatch(Actions.clearPermalink({})),
34      },
35      m('i.material-icons.disallow-selection', 'close')),
36  ]);
37}
38
39class Alerts implements m.ClassComponent {
40  view() {
41    return m('.alerts', renderPermalink());
42  }
43}
44
45/**
46 * Wrap component with common UI elements (nav bar etc).
47 */
48export function createPage(component: m.Component): m.Component {
49  const pageComponent = {
50    view() {
51      const children = [
52        m(Sidebar),
53        m(Topbar),
54        m(Alerts),
55        m(component),
56        m(CookieConsent),
57      ];
58      if (globals.frontendLocalState.perfDebug) {
59        children.push(m('.perf-stats'));
60      }
61      return children;
62    },
63  };
64
65  return pageComponent;
66}
67