Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {LitElement} from 'lit-element'; |
| 6 | import qs from 'qs'; |
| 7 | import {store, connectStore} from 'reducers/base.js'; |
| 8 | import * as userV0 from 'reducers/userV0.js'; |
| 9 | import * as projectV0 from 'reducers/projectV0.js'; |
| 10 | import * 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 | */ |
| 20 | export 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 | } |
| 62 | customElements.define('ezt-app-base', EztAppBase); |