|
| 1 | +<script lang="ts"> |
| 2 | +import { computed, defineComponent, ref } from 'vue' |
| 3 | +import { BButton } from 'bootstrap-vue' |
| 4 | +
|
| 5 | +import { adaptHtmlElementAsyncFn } from '@/visualEngine/adaptHtmlElementAsync' |
| 6 | +import { code2Settings, getLangConfig } from '@readapt/settings' |
| 7 | +import { AdaptContainer, SaveSettings } from '@readapt/shared-components' |
| 8 | +import { saveSettings } from '@/store' |
| 9 | +import utils from '@/chrome' |
| 10 | +
|
| 11 | +const { closeCurrentTab } = utils |
| 12 | +
|
| 13 | +const SettingsCodeEdit = defineComponent({ |
| 14 | + components: { BButton, AdaptContainer, SaveSettings }, |
| 15 | + setup() { |
| 16 | + const code = ref<string>('') |
| 17 | +
|
| 18 | + const settings = computed(() => { |
| 19 | + try { |
| 20 | + return code2Settings(code.value) |
| 21 | + } catch (e) { |
| 22 | + //error |
| 23 | + } |
| 24 | + return undefined |
| 25 | + }) |
| 26 | +
|
| 27 | + const wrongCodeError = computed(() => { |
| 28 | + return code.value && !settings.value |
| 29 | + }) |
| 30 | +
|
| 31 | + const textPreview = computed(() => { |
| 32 | + const lang = settings.value ? settings.value.language : 'en' |
| 33 | + return getLangConfig(lang).textPreview |
| 34 | + }) |
| 35 | +
|
| 36 | + const applyCode = () => { |
| 37 | + if (settings.value) { |
| 38 | + saveSettings(settings.value) |
| 39 | + } |
| 40 | + } |
| 41 | +
|
| 42 | + const close = async () => { |
| 43 | + await closeCurrentTab() |
| 44 | + } |
| 45 | +
|
| 46 | + return { |
| 47 | + adaptHtmlElementAsyncFn, |
| 48 | + applyCode, |
| 49 | + close, |
| 50 | + textPreview, |
| 51 | + settings, |
| 52 | + code, |
| 53 | + wrongCodeError |
| 54 | + } |
| 55 | + } |
| 56 | +}) |
| 57 | +export default SettingsCodeEdit |
| 58 | +</script> |
| 59 | +<template> |
| 60 | + <div class="container-fluid"> |
| 61 | + <div class="my-4"> |
| 62 | + <h2>{{ $t('SETTINGS_CODE.APPLY_YOUR_SETTINGS_CODE') }}</h2> |
| 63 | + </div> |
| 64 | + <div> |
| 65 | + <textarea class="form-control" rows="5" :placeholder="$t('SETTINGS_CODE.PASTE_YOUR_SETTINGS')" v-model="code"></textarea> |
| 66 | + </div> |
| 67 | + |
| 68 | + <div class="d-flex flex-column align-content-between h-100"> |
| 69 | + <div class="mt-3 d-flex justify-content-between"> |
| 70 | + <SaveSettings @save-settings="applyCode()" :disabled="!settings" label="SETTINGS_CODE.APPLY_THIS_SETTINGS" /> |
| 71 | + <b-button size="sm" variant="outline-primary" @click="close()"> {{ $t('SETTINGS.CLOSE') }}</b-button> |
| 72 | + </div> |
| 73 | + |
| 74 | + <p v-if="wrongCodeError" class="text-danger my-2">{{ $t('SETTINGS_CODE.WRONG_CODE_ERROR') }}</p> |
| 75 | + |
| 76 | + <template v-if="settings"> |
| 77 | + <h3 class="my-4">{{ $t('SETTINGS.TEXT_PREVIEW') }}</h3> |
| 78 | + |
| 79 | + <AdaptContainer |
| 80 | + class="settings-code-preview" |
| 81 | + :adapt-html-element-async="adaptHtmlElementAsyncFn()" |
| 82 | + :content-to-adapt="$sanitize('<p>' + textPreview + '</p>')" |
| 83 | + :settings="settings" |
| 84 | + scope="settings-code-preview" |
| 85 | + /> |
| 86 | + </template> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | +</template> |
| 90 | +<style scoped></style> |
0 commit comments