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,55 +16,49 @@
</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 { const list = reactive(new ListModel())
list: new ListModel(), const props = defineProps({
foundLists: [],
}
},
props: {
modelValue: { modelValue: {
validator(value) {
return value instanceof ListModel
},
required: false, required: false,
}, },
}, })
emits: ['update:modelValue', 'selected'], const emit = defineEmits(['update:modelValue'])
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) { watchEffect(() => {
this.list = list Object.assign(list, props.modelValue)
this.$emit('selected', list) })
this.$emit('update:modelValue', list)
},
namespace(namespaceId) { const foundLists = ref([])
const namespace = this.$store.getters['namespaces/getNamespaceById'](namespaceId) function findLists(query: string) {
if (namespace !== null) { if (query === '') {
return namespace.title select(null)
} }
return this.$t('list.shared') 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>

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({
message: t('user.settings.appearance.setSuccess', {
colorScheme: colorSchemeSettings.value[schemeId], colorScheme: colorSchemeSettings.value[schemeId],
})}) }),
})
}) })
return { return {
@ -178,9 +182,14 @@ 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: {
get() {
return this.$store.getters['lists/getListById'](this.settings.defaultListId) return this.$store.getters['lists/getListById'](this.settings.defaultListId)
}, },
set(l) {
this.settings.defaultListId = l ? l.id : DEFAULT_LIST_ID
},
},
}, },
setup() { setup() {
@ -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')})
}, },
}, },