[web] Refactor input field for URLs

This commit is contained in:
Alain Nussbaumer 2025-02-16 20:42:08 +01:00
parent b5c7dfaf59
commit b460be8873
3 changed files with 77 additions and 68 deletions

View File

@ -0,0 +1,50 @@
<template>
<div class="field">
<p class="control has-icons-left">
<input
ref="input"
v-model="url"
class="input"
type="url"
pattern="http[s]?://.+"
required
:placeholder="placeholder"
:disabled="loading"
@input="validate"
/>
<mdicon class="icon is-left" :name="icon" size="16" />
</p>
<p v-if="help" class="help" v-text="help" />
</div>
</template>
<script>
export default {
name: 'ControlUrlField',
props: {
placeholder: { type: String, required: true },
icon: { type: String, required: true },
help: { type: String, default: '' },
loading: { type: Boolean, default: false }
},
emits: ['url-changed'],
data() {
return {
url: '',
disabled: true
}
},
mounted() {
setTimeout(() => {
this.$refs.input.focus()
}, 10)
},
methods: {
validate(event) {
const { validity } = event.target
this.disabled = validity.patternMismatch || validity.valueMissing
this.$emit('url-changed', this.url, this.disabled)
}
}
}
</script>

View File

@ -6,40 +6,31 @@
@close="$emit('close')" @close="$emit('close')"
> >
<template #content> <template #content>
<div class="field"> <control-url-field
<p class="control has-icons-left"> icon="rss"
<input :help="$t('dialog.add.rss.help')"
ref="url_field" :loading="loading"
v-model="url"
class="input"
type="url"
pattern="http[s]?://.+"
required
:placeholder="$t('dialog.add.rss.placeholder')" :placeholder="$t('dialog.add.rss.placeholder')"
:disabled="loading" @url-changed="onUrlChanged"
@input="check_url"
/> />
<mdicon class="icon is-left" name="rss" size="16" />
</p>
<p class="help" v-text="$t('dialog.add.rss.help')" />
</div>
</template> </template>
</modal-dialog> </modal-dialog>
</template> </template>
<script> <script>
import ControlUrlField from '@/components/ControlUrlField.vue'
import ModalDialog from '@/components/ModalDialog.vue' import ModalDialog from '@/components/ModalDialog.vue'
import webapi from '@/webapi' import webapi from '@/webapi'
export default { export default {
name: 'ModalDialogAddRss', name: 'ModalDialogAddRss',
components: { ModalDialog }, components: { ControlUrlField, ModalDialog },
props: { show: Boolean }, props: { show: Boolean },
emits: ['close', 'podcast-added'], emits: ['close', 'podcast-added'],
data() { data() {
return { return {
disabled: true,
loading: false, loading: false,
disabled: true,
url: '' url: ''
} }
}, },
@ -63,18 +54,11 @@ export default {
] ]
} }
}, },
watch: {
show() {
if (this.show) {
this.loading = false
// Delay setting the focus on the input field until it is part of the DOM and visible
setTimeout(() => {
this.$refs.url_field.focus()
}, 10)
}
}
},
methods: { methods: {
onUrlChanged(url, disabled) {
this.url = url
this.disabled = disabled
},
add() { add() {
this.loading = true this.loading = true
webapi webapi
@ -90,10 +74,6 @@ export default {
}, },
cancel() { cancel() {
this.$emit('close') this.$emit('close')
},
check_url(event) {
const { validity } = event.target
this.disabled = validity.patternMismatch || validity.valueMissing
} }
} }
} }

View File

@ -7,40 +7,31 @@
> >
<template #content> <template #content>
<form @submit.prevent="play"> <form @submit.prevent="play">
<div class="field"> <control-url-field
<p class="control has-icons-left"> icon="web"
<input :loading="loading"
ref="url_field"
v-model="url"
class="input"
type="url"
pattern="http[s]?://.+"
required
:placeholder="$t('dialog.add.stream.placeholder')" :placeholder="$t('dialog.add.stream.placeholder')"
:disabled="loading" @url-changed="onUrlChanged"
@input="check_url"
/> />
<mdicon class="icon is-left" name="web" size="16" />
</p>
</div>
</form> </form>
</template> </template>
</modal-dialog> </modal-dialog>
</template> </template>
<script> <script>
import ControlUrlField from '@/components/ControlUrlField.vue'
import ModalDialog from '@/components/ModalDialog.vue' import ModalDialog from '@/components/ModalDialog.vue'
import webapi from '@/webapi' import webapi from '@/webapi'
export default { export default {
name: 'ModalDialogAddStream', name: 'ModalDialogAddStream',
components: { ModalDialog }, components: { ControlUrlField, ModalDialog },
props: { show: Boolean }, props: { show: Boolean },
emits: ['close'], emits: ['close'],
data() { data() {
return { return {
disabled: true,
loading: false, loading: false,
disabled: true,
url: '' url: ''
} }
}, },
@ -70,18 +61,11 @@ export default {
] ]
} }
}, },
watch: {
show() {
if (this.show) {
this.loading = false
// Delay setting the focus on the input field until it is part of the DOM and visible
setTimeout(() => {
this.$refs.url_field.focus()
}, 10)
}
}
},
methods: { methods: {
onUrlChanged(url, disabled) {
this.url = url
this.disabled = disabled
},
add() { add() {
this.loading = true this.loading = true
webapi webapi
@ -97,11 +81,6 @@ export default {
cancel() { cancel() {
this.$emit('close') this.$emit('close')
}, },
check_url(event) {
const { validity } = event.target
this.disabled = validity.patternMismatch || validity.valueMissing
},
play() { play() {
this.loading = true this.loading = true
webapi webapi