fix: saving default list #1143
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#1143
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/task-create-list"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Relevant forum discussion: https://community.vikunja.io/t/quick-add-magic-for-list-not-working/493/3
@ -183,0 +184,4 @@
get() {
return this.$store.getters['lists/getListById'](this.settings.defaultListId)
},
set(l) {
It looks like this does not even generate an error message.
@dpschen Any idea why?
Why should it generate one? I think I need more context.
Regardless:
This seems like the wrong location to set a default value.
0
isn't recognizable as such.I think at least it should be a const (e.g.
DEFAULT_LIST_ID
).Maybe better: creating a defaultList getter in the store and use that everywhere where we need the defaultList. Because else we will repeat the returning of the defaultListId as
0
over and over =)Because I'm trying to assign to a computed value. It works with a setter, but doesn't this should throw an error?
But here in this case I want to query the set default list from the component instead of the one currently saved in the store. Having a getter in the store with a function property that's only used once seems a bit pointless.
Not really sure how to improve this. Added a
DEFAULT_LIST_ID
const for now, maybe that already improves things a bit.So if you set the defaultListId to
0
that means there is none, right?EDIT: in the sense of: we reset the defaultListId
If that's the reason for the
0
then maybe we should just use that value when sending to the service.Or even better using this as a formatter inside the service.
So if
userSettingsService.update
is called with an settings object wheredefaultListId
is undefined just replace that withdefaultListId: 0
before sending to the server (?)Hi konrad!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://1143-fixtask-create-list--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
@ -38,2 +38,4 @@
Multiselect,
},
mounted() {
this.list = this.modelValue
It looks like the watcher does not get called, despite
immediate
set totrue
.@dpschen Do you have an idea why that is the case?
See the other comment
Note to self: imrove the error message when the list was not found (no default list set or none provided via quick add magic) to tell the users they need to provide a list
@ -458,3 +458,3 @@
font-family: $family-sans-serif;
font-weight: normal;
padding: .5rem 0;
padding: .5rem .5rem;
padding: .5rem;
Done.
@ -2,3 +2,3 @@
<multiselect
class="control is-expanded"
:placeholder="$t('list.search')"
:placeholder="t('list.search')"
$t
is undefined?It actually isn't! I just thought I needed to use
t
since I'm importing it already. Changed it.I'm not sure what way is actually the better one because later we might need to change everything in
t
or write our own injection as far as I can remeber the vue-i18n 9 documentation.@ -39,0 +38,4 @@
watch(
() => props.modelValue,
value => {
list = value
I think you need to use
Object.assign
for a reactive here. Because else you will replace the reactive with the static data coming from the propmodelValue
.Or use a
ref
. But then you need to assign tolist.value
If you use
watchEffect
here you can save the definition of what to watch (vue does that automatically). Also it runs initially by default, so no need forimmediate: true
.Also there is a spelling error (it is
immeditate: true,
right now), so that might also be a problem.Sidenote: vueuse useVModel might also be of help for the value syncing here).
I thought
ref
should be used preferrably for primitive types, not objects?wow now I feel a bit dumb 😄 It seems to work if I correct it.
watchEffect
seems to work great, switched it to this andObject.assign
.@ -66,2 +57,2 @@
},
},
function select(l) {
list = l
Use
Object.assign
@ -68,0 +62,4 @@
function namespace(namespaceId) {
const namespace = store.getters['namespaces/getNamespaceById'](namespaceId)
if (namespace !== null) {
Done.
Maybe related:
I also realized that there is no default list initially.
So even if it returns
0
will this work?It wont work in that case. The default list is 0 because that's the nil value of an int in Go. Setting it to 0 matches that behaviour but is not ideal.
@ -35,0 +26,4 @@
const store = useStore()
const {t} = useI18n()
let list = reactive(new ListModel())
A reactive has to be a
const
. If you reassign it, it wouldn't be a reactive anymore. Same goes for refs.If you think of refs as reactives with just one exposed prop that is named value it's easier to understand.
Also good to know is that vues reactivity is now based on Proxies. When you know this it makes sense that reactivity works only on the objects props (
.value
/ the props of a reactive) and you cannot simply replace the proxy.(if you knew all of that, tell me and I'll stop explaing)
Thanks for the explanation, that makes a lot of sense.
No worries! I kind of know bits and pieces of it, not the whole thing :)
@ -51,2 +47,2 @@
this.foundLists = this.$store.getters['lists/searchList'](query)
},
)
list = props.modelValue
I overlooked this when I first checked this.
With the watcher / watchEffect this shouldn't be necessary.
Yes, this works.
@ -67,1 +57,3 @@
},
function select(l) {
list = l
emit('selected', list)
I think we should remove the
selected
and only useupdate:modelValue
to reduce complexity, since they are doing the same.I didn't know you could listen to
update:modelValue
explicitly. Removedselected
.AFAIK it really is just a convention, other than that a regular event.
@ -205,3 +214,3 @@
saveLanguage(this.language)
setQuickAddMagicMode(this.quickAddMagicMode)
this.settings.defaultListId = this.defaultList ? this.defaultList.id : 0
this.settings.defaultListId = this.defaultList ? this.defaultList.id : DEFAULT_LIST_ID
Since this is before sending to the server we should just create a new object here (and not modify the settings directly). Something like (super untested):
Changed it to do just that. The api does not return the new settings though, only a success message - I'm committing the settings object built previously.
@ -478,3 +478,3 @@
color: transparent;
transition: color $transition;
padding: 0 .5rem;
padding-left: .5rem;
Not sure if by intend: you removed the
padding-right
.Yes that was intended because the text on the right "press enter or click to select" already has padding.
@ -18,3 +18,2 @@
<script>
import ListModel from '../../../models/list'
<script setup>
Use ts
I don't know why but I can't seem to use the component anymore when I add it:
I don't know why it did not work previously, seems to work now.
@ -48,0 +27,4 @@
const {t} = useI18n()
const list = reactive(new ListModel())
let foundLists = ref([])
Ref
foundLists
should be a const.Move
foundLists
definition next to where it is used (the findLists function).=> Group by function; More vue composition way of doing things.
Done.
@ -48,0 +30,4 @@
let foundLists = ref([])
const props = defineProps({
modelValue: {
required: false,
Add type
I had to use a custom validation because the
ListModel
is not really a type.@ -68,0 +47,4 @@
}
function select(l) {
Object.assign(list, l)
Is the
Object.assign
here even needed?Asking because:
Since you emit the new value in the next line it should already be changed via the update of the modelValue in the watchEffect. In the sense of events up / props down.
Okay I just saw that modelValue is not required and also not always set (e.g. in the TaskDetailView).
Then of course it's still needed.
@ -211,2 +217,3 @@
const settings = {
...this.settings,
})
defaultListId: this.defaultList ? this.defaultList.id : DEFAULT_LIST_ID,
I think I know now what seemed of for me:
defaultListId should be a computed.
This way the logic
this.defaultList ? this.defaultList.id : DEFAULT_LIST_ID
does not have to be repeated here and in the defaultList setter.We actually don't need this at all due to the setter. I've removed it.
Didn't realize this aswell. Nice!