blob: 01710b436a75e7b8aa5b39b84ac401f5d30a69e8 [file] [log] [blame]
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +02001import '@material/web/fab/fab.js';
2import './components/List.js';
3import './components/AddDialog.js';
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +02004import './components/WorkflowDialog.js';
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +02005
6import {css, html, LitElement} from 'lit';
7import {createRef, ref} from 'lit/directives/ref.js';
8
9import {SHARED_MD3_STYLES} from '../../common/styles/md3.js';
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020010import {default as WorkflowsStorage, kWorkflowsDataKey} from '../workflowsStorage.js';
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020011
12export default class WFApp extends LitElement {
13 static styles = [
14 SHARED_MD3_STYLES,
15 css`
16 :host {
17 font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI',
18 Helvetica, Arial, sans-serif, 'Apple Color Emoji',
19 'Segoe UI Emoji', 'Segoe UI Symbol'!important;
20
21 display: block;
22 max-width: 1024px;
23 margin: auto;
24 position: relative;
25 }
26
27 md-fab {
28 position: fixed;
29 bottom: 2em;
30 right: 2em;
31 }
32 `,
33 ];
34
35 addFabRef = createRef();
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020036 addDialog = createRef();
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020037
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020038 constructor() {
39 super();
40 this._workflows = undefined;
41 this._updateWorkflows();
42 chrome.storage.onChanged.addListener((changes, areaName) => {
43 if (areaName == 'local' && changes[kWorkflowsDataKey])
44 this._updateWorkflows();
45 });
46 }
47
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020048 render() {
49 return html`
50 <h1>Workflows</h1>
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020051 <p>Workflows allow you to run a customized list of actions on a thread easily.</p>
52 <wf-list .workflows=${this._workflows}></wf-list>
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020053 <md-fab ${ref(this.addFabRef)}
54 icon="add"
55 @click=${this._showAddDialog}>
56 </md-fab>
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020057 <wf-add-dialog ${ref(this.addDialog)}>
58 </wf-add-dialog>
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020059 `;
60 }
61
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +020062 _updateWorkflows() {
63 WorkflowsStorage.getAll(/* asProtobuf = */ true).then(workflows => {
64 this._workflows = workflows;
65 this.requestUpdate();
66 });
67 }
68
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020069 _showAddDialog() {
Adrià Vilanova Martínez8803b6c2022-10-17 00:36:38 +020070 this.addDialog.value.open = true;
Adrià Vilanova Martínezf276ac72022-10-13 22:16:22 +020071 }
72}
73window.customElements.define('wf-app', WFApp);