blob: 7813a160b69761e63c48ea2780f370cc26805ac1 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {LitElement} from 'lit-element';
6import qs from 'qs';
7import {store, connectStore} from 'reducers/base.js';
8import * as userV0 from 'reducers/userV0.js';
9import * as projectV0 from 'reducers/projectV0.js';
10import * as sitewide from 'reducers/sitewide.js';
11
12/**
13 * `<ezt-app-base>`
14 *
15 * Base component meant to simulate a subset of the work mr-app does on
16 * EZT pages in order to allow us to more easily glue web components
17 * on EZT pages to SPA web components.
18 *
19 */
20export class EztAppBase extends connectStore(LitElement) {
21 /** @override */
22 static get properties() {
23 return {
24 projectName: {type: String},
25 userDisplayName: {type: String},
26 };
27 }
28
29 /** @override */
30 connectedCallback() {
31 super.connectedCallback();
32
33 this.mapUrlToQueryParams();
34 }
35
36 /** @override */
37 updated(changedProperties) {
38 if (changedProperties.has('userDisplayName') && this.userDisplayName) {
39 this.fetchUserData(this.userDisplayName);
40 }
41
42 if (changedProperties.has('projectName') && this.projectName) {
43 this.fetchProjectData(this.projectName);
44 }
45 }
46
47 fetchUserData(displayName) {
48 store.dispatch(userV0.fetch(displayName));
49 }
50
51 fetchProjectData(projectName) {
52 store.dispatch(projectV0.select(projectName));
53 store.dispatch(projectV0.fetch(projectName));
54 }
55
56 mapUrlToQueryParams() {
57 const params = qs.parse((window.location.search || '').substr(1));
58
59 store.dispatch(sitewide.setQueryParams(params));
60 }
61}
62customElements.define('ezt-app-base', EztAppBase);