fix: saving default list (#1143)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1143
Reviewed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
Co-authored-by: konrad <k@knt.li>
Co-committed-by: konrad <k@knt.li>
This commit is contained in:
konrad 2021-12-13 22:20:45 +00:00
parent 40479d0c6e
commit 543dae2f30
4 changed files with 62 additions and 58 deletions

View file

@ -457,7 +457,7 @@ export default {
text-transform: none; text-transform: none;
font-family: $family-sans-serif; font-family: $family-sans-serif;
font-weight: normal; font-weight: normal;
padding: .5rem 0; padding: .5rem;
border: none; border: none;
cursor: pointer; cursor: pointer;
@ -477,7 +477,7 @@ export default {
font-size: .75rem; font-size: .75rem;
color: transparent; color: transparent;
transition: color $transition; transition: color $transition;
padding: 0 .5rem; padding-left: .5rem;
} }
&:focus, &:hover { &:focus, &:hover {

View file

@ -16,60 +16,54 @@
</multiselect> </multiselect>
</template> </template>
<script> <script lang="ts" setup>
import ListModel from '../../../models/list' import {reactive, ref, watchEffect} from 'vue'
import {useStore} from 'vuex'
import {useI18n} from 'vue-i18n'
import ListModel from '@/models/list'
import Multiselect from '@/components/input/multiselect.vue' import Multiselect from '@/components/input/multiselect.vue'
export default { const store = useStore()
name: 'listSearch', const {t} = useI18n()
data() {
return {
list: new ListModel(),
foundLists: [],
}
},
props: {
modelValue: {
required: false,
},
},
emits: ['update:modelValue', 'selected'],
components: {
Multiselect,
},
watch: {
modelValue: {
handler(value) {
this.list = value
},
immeditate: true,
deep: true,
},
},
methods: {
findLists(query) {
this.foundLists = this.$store.getters['lists/searchList'](query)
},
select(list) { const list = reactive(new ListModel())
this.list = list const props = defineProps({
this.$emit('selected', list) modelValue: {
this.$emit('update:modelValue', list) validator(value) {
}, return value instanceof ListModel
namespace(namespaceId) {
const namespace = this.$store.getters['namespaces/getNamespaceById'](namespaceId)
if (namespace !== null) {
return namespace.title
}
return this.$t('list.shared')
}, },
required: false,
}, },
})
const emit = defineEmits(['update:modelValue'])
watchEffect(() => {
Object.assign(list, props.modelValue)
})
const foundLists = ref([])
function findLists(query: string) {
if (query === '') {
select(null)
}
foundLists.value = store.getters['lists/searchList'](query)
}
function select(l: ListModel | null) {
Object.assign(list, l)
emit('update:modelValue', list)
}
function namespace(namespaceId: number) {
const namespace = store.getters['namespaces/getNamespaceById'](namespaceId)
return namespace !== null
? namespace.title
: t('list.shared')
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.list-namespace-title { .list-namespace-title {
color: var(--grey-500); color: var(--grey-500);
} }
</style> </style>

View file

@ -238,7 +238,7 @@
</h3> </h3>
<div class="field has-addons"> <div class="field has-addons">
<div class="control is-expanded"> <div class="control is-expanded">
<list-search @selected="changeList" ref="moveList"/> <list-search @update:modelValue="changeList" ref="moveList"/>
</div> </div>
</div> </div>
</div> </div>

View file

@ -131,8 +131,10 @@ import {playPop} from '@/helpers/playPop'
import {useColorScheme} from '@/composables/useColorScheme' import {useColorScheme} from '@/composables/useColorScheme'
import {success} from '@/message' import {success} from '@/message'
const DEFAULT_LIST_ID = 0
function useColorSchemeSetting() { function useColorSchemeSetting() {
const { t } = useI18n() const {t} = useI18n()
const colorSchemeSettings = computed(() => ({ const colorSchemeSettings = computed(() => ({
light: t('user.settings.appearance.colorScheme.light'), light: t('user.settings.appearance.colorScheme.light'),
auto: t('user.settings.appearance.colorScheme.system'), auto: t('user.settings.appearance.colorScheme.system'),
@ -141,9 +143,11 @@ function useColorSchemeSetting() {
const {store} = useColorScheme() const {store} = useColorScheme()
watch(store, (schemeId) => { watch(store, (schemeId) => {
success({message: t('user.settings.appearance.setSuccess', { success({
colorScheme: colorSchemeSettings.value[schemeId], message: t('user.settings.appearance.setSuccess', {
})}) colorScheme: colorSchemeSettings.value[schemeId],
}),
})
}) })
return { return {
@ -178,8 +182,13 @@ export default {
.map(l => ({code: l[0], title: l[1]})) .map(l => ({code: l[0], title: l[1]}))
.sort((a, b) => a.title.localeCompare(b.title)) .sort((a, b) => a.title.localeCompare(b.title))
}, },
defaultList() { defaultList: {
return this.$store.getters['lists/getListById'](this.settings.defaultListId) get() {
return this.$store.getters['lists/getListById'](this.settings.defaultListId)
},
set(l) {
this.settings.defaultListId = l ? l.id : DEFAULT_LIST_ID
},
}, },
}, },
@ -204,12 +213,13 @@ export default {
localStorage.setItem(playSoundWhenDoneKey, this.playSoundWhenDone) localStorage.setItem(playSoundWhenDoneKey, this.playSoundWhenDone)
saveLanguage(this.language) saveLanguage(this.language)
setQuickAddMagicMode(this.quickAddMagicMode) setQuickAddMagicMode(this.quickAddMagicMode)
this.settings.defaultListId = this.defaultList ? this.defaultList.id : 0
await this.userSettingsService.update(this.settings) const settings = {
this.$store.commit('auth/setUserSettings', {
...this.settings, ...this.settings,
}) }
await this.userSettingsService.update(settings)
this.$store.commit('auth/setUserSettings', settings)
this.$message.success({message: this.$t('user.settings.general.savedSuccess')}) this.$message.success({message: this.$t('user.settings.general.savedSuccess')})
}, },
}, },