refactor sizesetting into unitsetting allowing more unit types with i18n support

This commit is contained in:
Henry Jameson 2024-04-24 15:58:26 +03:00
parent def68e9cda
commit 6ff0a7f021
9 changed files with 38 additions and 36 deletions

View File

@ -17,6 +17,10 @@ export default {
units: { units: {
type: Array, type: Array,
default: () => allCssUnits default: () => allCssUnits
},
unitSet: {
type: String,
default: 'none'
} }
}, },
computed: { computed: {
@ -30,6 +34,10 @@ export default {
}, },
methods: { methods: {
...Setting.methods, ...Setting.methods,
getUnitString (value) {
if (this.unitSet === 'none') return value
return this.$t(['settings', 'units', this.unitSet, value].join('.'))
},
updateValue (e) { updateValue (e) {
this.configSink(this.path, parseInt(e.target.value) + this.stateUnit) this.configSink(this.path, parseInt(e.target.value) + this.stateUnit)
}, },

View File

@ -1,7 +1,7 @@
<template> <template>
<span <span
v-if="matchesExpertLevel" v-if="matchesExpertLevel"
class="SizeSetting" class="UnitSetting"
> >
<label <label
:for="path" :for="path"
@ -23,7 +23,7 @@
:id="path" :id="path"
:model-value="stateUnit" :model-value="stateUnit"
:disabled="disabled" :disabled="disabled"
class="css-unit-input" class="unit-input unstyled"
@change="updateUnit" @change="updateUnit"
> >
<option <option
@ -31,7 +31,7 @@
:key="option" :key="option"
:value="option" :value="option"
> >
{{ option }} {{ getUnitString(option) }}
</option> </option>
</Select> </Select>
{{ ' ' }} {{ ' ' }}
@ -42,20 +42,19 @@
</span> </span>
</template> </template>
<script src="./size_setting.js"></script> <script src="./unit_setting.js"></script>
<style lang="scss"> <style lang="scss">
.SizeSetting { .UnitSetting {
.number-input { .number-input {
max-width: 6.5em; max-width: 6.5em;
text-align: right;
} }
.css-unit-input, .unit-input,
.css-unit-input select { .unit-input select {
margin-left: 0.5em;
width: 4em;
max-width: 4em;
min-width: 4em; min-width: 4em;
width: auto;
} }
} }

View File

@ -1,10 +1,8 @@
@import "src/variables";
.settings_tab-switcher { .settings_tab-switcher {
height: 100%; height: 100%;
.setting-item { .setting-item {
border-bottom: 2px solid var(--fg, $fallback--fg); border-bottom: 2px solid var(--border);
margin: 1em 1em 1.4em; margin: 1em 1em 1.4em;
padding-bottom: 1.4em; padding-bottom: 1.4em;
@ -33,10 +31,6 @@
margin-bottom: 1em; margin-bottom: 1em;
} }
select {
min-width: 10em;
}
textarea { textarea {
width: 100%; width: 100%;
max-width: 100%; max-width: 100%;
@ -45,8 +39,7 @@
.unavailable, .unavailable,
.unavailable svg { .unavailable svg {
color: var(--cRed, $fallback--cRed); color: var(--cRed);
color: $fallback--cRed;
} }
} }
} }

View File

@ -1,10 +1,8 @@
@import "src/variables";
.settings_tab-switcher { .settings_tab-switcher {
height: 100%; height: 100%;
.setting-item { .setting-item {
border-bottom: 2px solid var(--fg, $fallback--fg); border-bottom: 2px solid var(--border);
margin: 1em 1em 1.4em; margin: 1em 1em 1.4em;
padding-bottom: 1.4em; padding-bottom: 1.4em;
@ -33,10 +31,6 @@
margin-bottom: 1em; margin-bottom: 1em;
} }
select {
min-width: 10em;
}
textarea { textarea {
width: 100%; width: 100%;
max-width: 100%; max-width: 100%;
@ -45,8 +39,7 @@
.unavailable, .unavailable,
.unavailable svg { .unavailable svg {
color: var(--cRed, $fallback--cRed); color: var(--cRed);
color: $fallback--cRed;
} }
} }
} }

View File

@ -1,7 +1,7 @@
import { filter, trim, debounce } from 'lodash' import { filter, trim, debounce } from 'lodash'
import BooleanSetting from '../helpers/boolean_setting.vue' import BooleanSetting from '../helpers/boolean_setting.vue'
import ChoiceSetting from '../helpers/choice_setting.vue' import ChoiceSetting from '../helpers/choice_setting.vue'
import SizeSetting from '../helpers/size_setting.vue' import UnitSetting from '../helpers/unit_setting.vue'
import IntegerSetting from '../helpers/integer_setting.vue' import IntegerSetting from '../helpers/integer_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
@ -20,7 +20,7 @@ const FilteringTab = {
components: { components: {
BooleanSetting, BooleanSetting,
ChoiceSetting, ChoiceSetting,
SizeSetting, UnitSetting,
IntegerSetting IntegerSetting
}, },
computed: { computed: {

View File

@ -97,14 +97,15 @@
</BooleanSetting> </BooleanSetting>
</li> </li>
<li> <li>
<SizeSetting <UnitSetting
key="hideScrobblesAfter" key="hideScrobblesAfter"
path="hideScrobblesAfter" path="hideScrobblesAfter"
:units="['m', 'h', 'd']" :units="['m', 'h', 'd']"
unitSet="time"
expert="1" expert="1"
> >
{{ $t('settings.hide_scrobbles_after') }} {{ $t('settings.hide_scrobbles_after') }}
</SizeSetting> </UnitSetting>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -3,7 +3,7 @@ import ChoiceSetting from '../helpers/choice_setting.vue'
import ScopeSelector from 'src/components/scope_selector/scope_selector.vue' import ScopeSelector from 'src/components/scope_selector/scope_selector.vue'
import IntegerSetting from '../helpers/integer_setting.vue' import IntegerSetting from '../helpers/integer_setting.vue'
import FloatSetting from '../helpers/float_setting.vue' import FloatSetting from '../helpers/float_setting.vue'
import SizeSetting, { defaultHorizontalUnits } from '../helpers/size_setting.vue' import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue'
import InterfaceLanguageSwitcher from 'src/components/interface_language_switcher/interface_language_switcher.vue' import InterfaceLanguageSwitcher from 'src/components/interface_language_switcher/interface_language_switcher.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
@ -64,7 +64,7 @@ const GeneralTab = {
ChoiceSetting, ChoiceSetting,
IntegerSetting, IntegerSetting,
FloatSetting, FloatSetting,
SizeSetting, UnitSetting,
InterfaceLanguageSwitcher, InterfaceLanguageSwitcher,
ScopeSelector, ScopeSelector,
ProfileSettingIndicator ProfileSettingIndicator

View File

@ -134,7 +134,7 @@
<li v-if="expertLevel > 0"> <li v-if="expertLevel > 0">
{{ $t('settings.column_sizes') }} {{ $t('settings.column_sizes') }}
<div class="column-settings"> <div class="column-settings">
<SizeSetting <UnitSetting
v-for="column in columns" v-for="column in columns"
:key="column" :key="column"
:path="column + 'ColumnWidth'" :path="column + 'ColumnWidth'"
@ -142,7 +142,7 @@
expert="1" expert="1"
> >
{{ $t('settings.column_sizes_' + column) }} {{ $t('settings.column_sizes_' + column) }}
</SizeSetting> </UnitSetting>
</div> </div>
</li> </li>
<li class="select-multiple"> <li class="select-multiple">

View File

@ -395,6 +395,14 @@
"desc": "To enable two-factor authentication, enter the code from your two-factor app:" "desc": "To enable two-factor authentication, enter the code from your two-factor app:"
} }
}, },
"units": {
"time": {
"m": "minutes",
"s": "seconds",
"h": "hours",
"d": "days"
}
},
"lists_navigation": "Show lists in navigation", "lists_navigation": "Show lists in navigation",
"allow_following_move": "Allow auto-follow when following account moves", "allow_following_move": "Allow auto-follow when following account moves",
"attachmentRadius": "Attachments", "attachmentRadius": "Attachments",