|
| 1 | +<script lang="ts" setup> |
| 2 | +import { NFlex, NSelect, NText } from 'naive-ui'; |
| 3 | +
|
| 4 | +import { computed, ref } from 'vue'; |
| 5 | +
|
| 6 | +import type { Route } from '~/models/router.model'; |
| 7 | +
|
| 8 | +import SettingsFormItem from '~/components/views/settings/SettingsFormItem.vue'; |
| 9 | +import { |
| 10 | + type ImageFormat, |
| 11 | + type ImageType, |
| 12 | + useExtensionSettingsStore, |
| 13 | + useExtensionSettingsStoreRefs, |
| 14 | +} from '~/stores/settings/extension.store'; |
| 15 | +import { useI18n } from '~/utils/i18n.utils'; |
| 16 | +
|
| 17 | +const i18n = useI18n('settings', 'images'); |
| 18 | +
|
| 19 | +const { enabledTabs, imageType, imageFormat } = useExtensionSettingsStoreRefs(); |
| 20 | +const { setImageType, setImageFormat } = useExtensionSettingsStore(); |
| 21 | +
|
| 22 | +const typeOptions = computed<{ label: string; value: ImageType }[]>(() => [ |
| 23 | + { label: i18n('default', 'common', 'image', 'type'), value: 'default' }, |
| 24 | + { label: i18n('show', 'common', 'image', 'type'), value: 'show' }, |
| 25 | +]); |
| 26 | +
|
| 27 | +const formatOptions = computed<{ label: string; value: ImageFormat }[]>(() => [ |
| 28 | + { label: i18n('poster', 'common', 'image', 'format'), value: 'poster' }, |
| 29 | + { label: i18n('backdrop', 'common', 'image', 'format'), value: 'backdrop' }, |
| 30 | +]); |
| 31 | +
|
| 32 | +const toggleImageType = (tab: Route, current?: ImageType) => { |
| 33 | + setImageType(tab, current === 'default' ? 'show' : 'default'); |
| 34 | +}; |
| 35 | +
|
| 36 | +const toggleImageFormat = (tab: Route, current?: ImageFormat) => { |
| 37 | + setImageFormat(tab, current === 'poster' ? 'backdrop' : 'poster'); |
| 38 | +}; |
| 39 | +
|
| 40 | +const container = ref(); |
| 41 | +</script> |
| 42 | + |
| 43 | +<template> |
| 44 | + <div ref="container" class="image-container"> |
| 45 | + <NText class="description" tag="p">{{ i18n('image_format_type') }}</NText> |
| 46 | + <NFlex |
| 47 | + v-for="[tab] in enabledTabs" |
| 48 | + :key="tab" |
| 49 | + class="form-row" |
| 50 | + align="center" |
| 51 | + justify="space-between" |
| 52 | + > |
| 53 | + <NText class="form-header" tag="h3">{{ i18n(tab, 'route') }}</NText> |
| 54 | + <NFlex class="form-selects" align="center" justify="flex-end"> |
| 55 | + <!-- Image type --> |
| 56 | + <SettingsFormItem class="form-item" vertical> |
| 57 | + <NSelect |
| 58 | + class="form-select" |
| 59 | + :value="imageType[tab]" |
| 60 | + :to="container" |
| 61 | + :options="typeOptions" |
| 62 | + @update:value="toggleImageType(tab, imageType[tab])" |
| 63 | + /> |
| 64 | + </SettingsFormItem> |
| 65 | + |
| 66 | + <!-- Image format --> |
| 67 | + <SettingsFormItem class="form-item" vertical> |
| 68 | + <NSelect |
| 69 | + class="form-select" |
| 70 | + :value="imageFormat[tab]" |
| 71 | + :to="container" |
| 72 | + :options="formatOptions" |
| 73 | + @update:value="toggleImageFormat(tab, imageFormat[tab])" |
| 74 | + /> |
| 75 | + </SettingsFormItem> |
| 76 | + </NFlex> |
| 77 | + </NFlex> |
| 78 | + </div> |
| 79 | +</template> |
| 80 | + |
| 81 | +<style lang="scss" scoped> |
| 82 | +.image-container { |
| 83 | + display: flex; |
| 84 | + flex-direction: column; |
| 85 | + gap: 1.5rem; |
| 86 | +
|
| 87 | + .form-row { |
| 88 | + padding: 0.25rem 1rem; |
| 89 | + background: var(--bg-black-soft); |
| 90 | + border: 1px solid var(--white-10); |
| 91 | + border-radius: 0.5rem; |
| 92 | + transition: |
| 93 | + background 0.3s var(--n-bezier), |
| 94 | + border 0.3s var(--n-bezier); |
| 95 | +
|
| 96 | + &:active, |
| 97 | + &:focus-within, |
| 98 | + &:hover { |
| 99 | + border-color: var(--white-15); |
| 100 | + } |
| 101 | + } |
| 102 | +
|
| 103 | + .form-selects { |
| 104 | + flex: 1 1 70%; |
| 105 | + } |
| 106 | +
|
| 107 | + .form-select, |
| 108 | + .form-item { |
| 109 | + flex: 0 0 7rem; |
| 110 | + padding: 0 0.25rem; |
| 111 | + } |
| 112 | +
|
| 113 | + .form-header { |
| 114 | + flex: 0 1 20%; |
| 115 | + } |
| 116 | +
|
| 117 | + .description { |
| 118 | + white-space: pre-line; |
| 119 | + } |
| 120 | +} |
| 121 | +</style> |
0 commit comments