pleroma-fe/src/components/settings_modal/helpers/rate_setting.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-12-09 13:21:46 +02:00
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Setting from './setting.js'
export default {
...Setting,
2026-01-06 16:22:52 +02:00
data() {
2025-12-09 13:21:46 +02:00
return {
newValue: '',
}
},
components: {
...Setting.components,
2026-01-06 16:22:52 +02:00
Checkbox,
2025-12-09 13:21:46 +02:00
},
props: {
2026-01-06 16:22:52 +02:00
...Setting.props,
2025-12-09 13:21:46 +02:00
},
computed: {
...Setting.computed,
2026-01-06 16:22:52 +02:00
isSeparate() {
2025-12-09 13:21:46 +02:00
// [[a1, b1], [a2, b2]] vs [a, b]
return Array.isArray(this.visibleState[0])
},
2026-01-06 16:22:52 +02:00
normalizedState() {
2025-12-09 13:21:46 +02:00
if (this.isSeparate) {
2026-01-06 16:22:52 +02:00
return this.visibleState.map((y) => y.map((x) => Number(x) || 0))
2025-12-09 13:21:46 +02:00
} else {
2026-01-06 16:22:52 +02:00
return [this.visibleState.map((x) => Number(x) || 0)]
2025-12-09 13:21:46 +02:00
}
2026-01-06 16:22:52 +02:00
},
2025-12-09 13:21:46 +02:00
},
methods: {
...Setting.methods,
2026-01-06 16:22:52 +02:00
getValue({ event, side, index, eventType }) {
2025-12-09 13:21:46 +02:00
if (eventType === 'edit') {
const value = Number(event.target.value)
if (Number.isNaN(value)) return this.visibleState
2026-01-06 16:22:52 +02:00
const newVal = [...this.normalizedState.map((x) => [...x])]
2025-12-09 13:21:46 +02:00
newVal[side][index] = value
return newVal
}
if (eventType === 'toggleMode') {
if (event === 'split') {
return [this.normalizedState[0], this.normalizedState[0]]
} else if (event === 'join') {
return [this.normalizedState[0]]
}
}
2026-01-06 16:22:52 +02:00
},
},
2025-12-09 13:21:46 +02:00
}