Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 1 | import './languages-editor'; |
| 2 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 3 | import {css, html, LitElement} from 'lit'; |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 4 | import {customElement, property} from 'lit/decorators.js'; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 5 | import {map} from 'lit/directives/map.js'; |
| 6 | |
Adrià Vilanova Martínez | 5bdc473 | 2022-05-31 20:12:21 +0200 | [diff] [blame] | 7 | import {msg} from '../../../common/i18n'; |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 8 | import {OptionsV0, TAB_OPTIONS, TabOptionValue} from '../../../common/options'; |
Adrià Vilanova Martínez | 5bdc473 | 2022-05-31 20:12:21 +0200 | [diff] [blame] | 9 | import {SHARED_STYLES} from '../../shared/shared-styles'; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 10 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 11 | @customElement('options-editor') |
| 12 | export default class OptionsEditor extends LitElement { |
| 13 | @property({type: Object}) storageData: OptionsV0; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 14 | |
| 15 | static get styles() { |
| 16 | return [ |
| 17 | SHARED_STYLES, |
| 18 | css` |
| 19 | #otheroptions p { |
| 20 | margin-top: 0; |
| 21 | margin-bottom: 8px; |
| 22 | } |
| 23 | `, |
| 24 | ]; |
| 25 | } |
| 26 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 27 | render() { |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 28 | const currentTabOption = this.storageData?.uniquetab; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 29 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 30 | const otherOptions = map(TAB_OPTIONS, (option, i) => { |
| 31 | const checked = option.value == currentTabOption || |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 32 | option.deprecatedValues.includes(currentTabOption); |
| 33 | return html` |
| 34 | <p> |
| 35 | <input type="radio" name="uniquetab" id="uniquetab_${i}" |
Adrià Vilanova Martínez | 53f7a7f | 2022-05-30 13:59:59 +0200 | [diff] [blame] | 36 | value="${option?.value}" .checked="${checked}" |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 37 | @change="${() => this.changeTabOption(option.value)}"> |
| 38 | <label for="uniquetab_${i}">${msg(option.labelMsg)}</label></p> |
| 39 | `; |
| 40 | }); |
| 41 | |
| 42 | return html` |
| 43 | <languages-editor .languages="${this.storageData?.translateinto}"> |
| 44 | </languages-editor> |
| 45 | |
| 46 | <h2 id="otheroptionsheader">${msg('options_otheroptionsheader')}</h2> |
| 47 | |
| 48 | <div id="otheroptions"> |
| 49 | ${otherOptions} |
| 50 | </div> |
| 51 | `; |
| 52 | } |
| 53 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 54 | changeTabOption(value: TabOptionValue) { |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 55 | chrome.storage.sync.set({uniquetab: value}, function() { |
Adrià Vilanova Martínez | 86fda49 | 2022-05-31 15:05:21 +0200 | [diff] [blame] | 56 | chrome.runtime.sendMessage({action: 'clearTranslatorTab'}); |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 57 | }); |
| 58 | } |
| 59 | } |