Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 1 | import '@material/web/formfield/formfield.js'; |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 2 | import '@material/web/icon/icon.js'; |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 3 | import '@material/web/switch/switch.js'; |
| 4 | |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 5 | import consoleCommonStyles from '!!raw-loader!../../../../static/css/common/console.css'; |
| 6 | import {css, html, LitElement, nothing, unsafeCSS} from 'lit'; |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 7 | import {createRef, ref} from 'lit/directives/ref.js'; |
| 8 | |
| 9 | import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js'; |
| 10 | import {kEventFlattenThreadsUpdated} from '../constants.js'; |
| 11 | |
| 12 | export default class TwptThreadToolbarInject extends LitElement { |
| 13 | static properties = { |
| 14 | options: {type: Object}, |
| 15 | }; |
| 16 | |
| 17 | static styles = [ |
| 18 | SHARED_MD3_STYLES, |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 19 | css`${unsafeCSS(consoleCommonStyles)}`, |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 20 | css` |
| 21 | :host { |
| 22 | display: flex; |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 23 | flex-flow: row wrap; |
| 24 | align-items: center; |
| 25 | row-gap: 0.5rem; |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 26 | padding-top: 1.5rem; |
| 27 | padding-left: 0.25rem; |
| 28 | padding-right: 0.25rem; |
| 29 | padding-bottom: 0.5rem; |
| 30 | } |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 31 | |
| 32 | .badge-container { |
| 33 | padding-right: 0.5rem; |
| 34 | border-right: solid gray 1px; |
| 35 | margin-right: 0.5rem; |
| 36 | } |
| 37 | |
| 38 | .TWPT-badge { |
| 39 | --icon-size: 17px; |
| 40 | } |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 41 | `, |
| 42 | ]; |
| 43 | |
| 44 | nestedViewRef = createRef(); |
| 45 | |
| 46 | constructor() { |
| 47 | super(); |
| 48 | this.options = {}; |
| 49 | } |
| 50 | |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 51 | renderBadge() { |
| 52 | return html` |
| 53 | <div class="badge-container"> |
| 54 | <div class="TWPT-badge"> |
| 55 | <md-icon>repeat</md-icon> |
| 56 | </div> |
| 57 | </div> |
| 58 | `; |
| 59 | } |
| 60 | |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 61 | renderFlattenRepliesSwitch() { |
| 62 | if (!this.options.flattenthreads) return nothing; |
| 63 | |
| 64 | return html` |
| 65 | <md-formfield label="Nested view"> |
| 66 | <md-switch ${ref(this.nestedViewRef)} |
| 67 | ?selected=${!this.options?.flattenthreads_switch_enabled} |
| 68 | @click=${this._flattenThreadsChanged}> |
| 69 | </md-formfield> |
| 70 | `; |
| 71 | } |
| 72 | |
| 73 | render() { |
| 74 | return html` |
Adrià Vilanova Martínez | 2144f4f | 2023-04-12 23:16:17 +0200 | [diff] [blame^] | 75 | ${this.renderBadge()} |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 76 | ${this.renderFlattenRepliesSwitch()} |
| 77 | `; |
| 78 | } |
| 79 | |
| 80 | _flattenThreadsChanged() { |
| 81 | const enabled = !this.nestedViewRef.value.selected; |
| 82 | const e = new CustomEvent(kEventFlattenThreadsUpdated, { |
| 83 | bubbles: true, |
| 84 | composed: true, |
| 85 | detail: {enabled}, |
| 86 | }); |
| 87 | this.dispatchEvent(e); |
| 88 | } |
| 89 | } |
| 90 | window.customElements.define( |
| 91 | 'twpt-thread-toolbar-inject', TwptThreadToolbarInject); |