• 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 m from 'mithril';
16
17import {Actions} from '../common/actions';
18
19import {onClickCopy} from './clipboard';
20import {CookieConsent} from './cookie_consent';
21import {globals} from './globals';
22import {fullscreenModalContainer} from './modal';
23import {Sidebar} from './sidebar';
24import {Topbar} from './topbar';
25
26function renderPermalink(): m.Children {
27  const permalink = globals.state.permalink;
28  if (!permalink.requestId || !permalink.hash) return null;
29  const url = `${self.location.origin}/#!/?s=${permalink.hash}`;
30  const linkProps = {title: 'Click to copy the URL', onclick: onClickCopy(url)};
31
32  return m('.alert-permalink', [
33    m('div', 'Permalink: ', m(`a[href=${url}]`, linkProps, url)),
34    m('button',
35      {
36        onclick: () => globals.dispatch(Actions.clearPermalink({})),
37      },
38      m('i.material-icons.disallow-selection', 'close')),
39  ]);
40}
41
42class Alerts implements m.ClassComponent {
43  view() {
44    return m('.alerts', renderPermalink());
45  }
46}
47
48// Wrap component with common UI elements (nav bar etc).
49export function createPage(component: m.Component<PageAttrs>):
50    m.Component<PageAttrs> {
51  const pageComponent = {
52    view({attrs}: m.Vnode<PageAttrs>) {
53      const children = [
54        m(Sidebar),
55        m(Topbar),
56        m(Alerts),
57        m(component, attrs),
58        m(CookieConsent),
59        m(fullscreenModalContainer.mithrilComponent),
60      ];
61      if (globals.state.perfDebug) {
62        children.push(m('.perf-stats'));
63      }
64      return children;
65    },
66  };
67
68  return pageComponent;
69}
70
71export interface PageAttrs {
72  subpage?: string;
73}
74