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

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-12-08 17:09:07 +02:00
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Setting from './setting.js'
2026-01-06 16:22:52 +02:00
const getUrl = (state) =>
state?.tuple ? state.tuple[1] + ':' + state.tuple[2] : state
const getSocks = (state) => state?.tuple
2025-12-08 17:09:07 +02:00
export default {
...Setting,
2026-01-06 16:22:52 +02:00
data() {
2025-12-08 17:09:07 +02:00
return {
urlField: '',
2026-01-06 16:22:52 +02:00
socksField: false,
2025-12-08 17:09:07 +02:00
}
},
2026-01-06 16:22:52 +02:00
created() {
2025-12-08 17:09:07 +02:00
Setting.created()
this.urlField = getUrl(this.realDraftMode ? this.draft : this.state)
this.socksField = getSocks(this.realDraftMode ? this.draft : this.state)
},
computed: {
...Setting.computed,
// state that we'll show in the UI, i.e. transforming map into list
2026-01-06 16:22:52 +02:00
displayState() {
2025-12-08 17:09:07 +02:00
if (this.visibleState?.tuple) {
return this.visibleState.tuple[1] + ':' + this.visibleState.tuple[2]
}
return this.visibleState
},
2026-01-06 16:22:52 +02:00
socksState() {
2025-12-08 17:09:07 +02:00
return getSocks(this.visibleState)
2026-01-06 16:22:52 +02:00
},
2025-12-08 17:09:07 +02:00
},
components: {
...Setting.components,
2026-01-06 16:22:52 +02:00
Checkbox,
2025-12-08 17:09:07 +02:00
},
methods: {
...Setting.methods,
2026-01-06 16:22:52 +02:00
getValue({ event, isProxy }) {
2025-12-08 17:09:07 +02:00
if (isProxy) {
this.socksField = event
} else {
this.urlField = event.target.value
}
if (this.socksField) {
2026-01-06 16:22:52 +02:00
return { tuple: [':socks5', ...this.urlField.split(':')] }
2025-12-08 17:09:07 +02:00
} else {
return this.urlField
}
2026-01-06 16:22:52 +02:00
},
},
2025-12-08 17:09:07 +02:00
}