Add a v-model prop to listSearch

This commit is contained in:
kolaente 2021-07-17 22:14:24 +02:00
parent 8a3fe5daa2
commit a0f1913645
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 19 additions and 11 deletions

View File

@ -32,6 +32,11 @@ export default {
foundLists: [], foundLists: [],
} }
}, },
props: {
value: {
required: false,
},
},
components: { components: {
Multiselect, Multiselect,
}, },
@ -39,6 +44,14 @@ export default {
this.listSerivce = new ListService() this.listSerivce = new ListService()
this.list = new ListModel() this.list = new ListModel()
}, },
watch: {
value(newVal) {
this.list = newVal
},
},
mounted() {
this.list = this.value
},
methods: { methods: {
findLists(query) { findLists(query) {
if (query === '') { if (query === '') {
@ -58,7 +71,9 @@ export default {
this.$set(this, 'foundLists', []) this.$set(this, 'foundLists', [])
}, },
select(list) { select(list) {
this.list = list
this.$emit('selected', list) this.$emit('selected', list)
this.$emit('input', list)
}, },
namespace(namespaceId) { namespace(namespaceId) {
const namespace = this.$store.getters['namespaces/getNamespaceById'](namespaceId) const namespace = this.$store.getters['namespaces/getNamespaceById'](namespaceId)

View File

@ -20,7 +20,7 @@
<label class="label"> <label class="label">
{{ $t('user.settings.general.defaultList') }} {{ $t('user.settings.general.defaultList') }}
</label> </label>
<list-search @selected="changeList"/> <list-search v-model="defaultList"/>
</div> </div>
<div class="field"> <div class="field">
<label class="checkbox"> <label class="checkbox">
@ -281,7 +281,6 @@ import TotpModel from '../../models/totp'
import TotpService from '../../services/totp' import TotpService from '../../services/totp'
import UserSettingsService from '../../services/userSettings' import UserSettingsService from '../../services/userSettings'
import UserSettingsModel from '../../models/userSettings' import UserSettingsModel from '../../models/userSettings'
import ListModel from '../../models/list'
import {playSoundWhenDoneKey} from '@/helpers/playPop' import {playSoundWhenDoneKey} from '@/helpers/playPop'
import {availableLanguages, saveLanguage, getCurrentLanguage} from '@/i18n/setup' import {availableLanguages, saveLanguage, getCurrentLanguage} from '@/i18n/setup'
@ -315,7 +314,7 @@ export default {
settings: UserSettingsModel, settings: UserSettingsModel,
userSettingsService: UserSettingsService, userSettingsService: UserSettingsService,
defaultList: ListModel, defaultList: null,
} }
}, },
components: { components: {
@ -337,10 +336,9 @@ export default {
this.playSoundWhenDone = localStorage.getItem(playSoundWhenDoneKey) === 'true' || localStorage.getItem(playSoundWhenDoneKey) === null this.playSoundWhenDone = localStorage.getItem(playSoundWhenDoneKey) === 'true' || localStorage.getItem(playSoundWhenDoneKey) === null
this.defaultList = null this.defaultList = this.$store.getters['lists/getListById'](this.settings.defaultListId)
this.totpStatus() this.totpStatus()
this.getListById()
}, },
mounted() { mounted() {
this.setTitle(this.$t('user.settings.title')) this.setTitle(this.$t('user.settings.title'))
@ -442,6 +440,7 @@ export default {
updateSettings() { updateSettings() {
localStorage.setItem(playSoundWhenDoneKey, this.playSoundWhenDone) localStorage.setItem(playSoundWhenDoneKey, this.playSoundWhenDone)
saveLanguage(this.language) saveLanguage(this.language)
this.settings.defaultListId = this.defaultList.id
this.userSettingsService.update(this.settings) this.userSettingsService.update(this.settings)
.then(() => { .then(() => {
@ -453,12 +452,6 @@ export default {
copy(text) { copy(text) {
copy(text) copy(text)
}, },
changeList(list) {
this.settings.defaultListId = list.id
},
getListById() {
this.defaultList = this.$store.getters['lists/getListById'](this.settings.defaultListId)
},
}, },
} }
</script> </script>