1
0

Favorite lists (#237)

Remove/show favorites namespace if a task/list is the first to being marked as favorite

Add special case to prevent marking an archived list as favorite

Add marking a task as favorite  on namespaces page

Prevent toggling the favorite state for the favorites list

Add method to toggle list favorite in the menu

Add favorite icon to lists in menu

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/237
This commit is contained in:
konrad
2020-09-06 14:20:48 +00:00
parent 5a0ef73b54
commit f2fcf42639
7 changed files with 162 additions and 29 deletions

View File

@ -1,4 +1,7 @@
import Vue from 'vue'
import ListService from '@/services/list'
const FavoriteListsNamespace = -2
export default {
namespaced: true,
@ -22,4 +25,32 @@ export default {
return null
},
},
actions: {
toggleListFavorite(ctx, list) {
list.isFavorite = !list.isFavorite
const listService = new ListService()
return listService.update(list)
.then(r => {
if (r.isFavorite) {
ctx.commit('addList', r)
r.namespaceId = FavoriteListsNamespace
ctx.commit('namespaces/addListToNamespace', r, {root: true})
} else {
ctx.commit('namespaces/setListInNamespaceById', r, {root: true})
r.namespaceId = FavoriteListsNamespace
ctx.commit('namespaces/removeListFromNamespaceById', r, {root: true})
}
ctx.dispatch('namespaces/loadNamespacesIfFavoritesDontExist', null, {root: true})
ctx.dispatch('namespaces/removeFavoritesNamespaceIfEmpty', null, {root: true})
return Promise.resolve(r)
})
.catch(e => {
// Reset the list state to the initial one to avoid confusion for the user
list.isFavorite = !list.isFavorite
ctx.commit('addList', list)
return Promise.reject(e)
})
},
},
}

View File

@ -24,12 +24,14 @@ export default {
for (const n in state.namespaces) {
// We don't have the namespace id on the list which means we need to loop over all lists until we find it.
// FIXME: Not ideal at all - we should fix that at the api level.
for (const l in state.namespaces[n].lists) {
if (state.namespaces[n].lists[l].id === list.id) {
const namespace = state.namespaces[n]
namespace.lists[l] = list
Vue.set(state.namespaces, n, namespace)
return
if (state.namespaces[n].id === list.namespaceId) {
for (const l in state.namespaces[n].lists) {
if (state.namespaces[n].lists[l].id === list.id) {
const namespace = state.namespaces[n]
namespace.lists[l] = list
Vue.set(state.namespaces, n, namespace)
return
}
}
}
}
@ -45,6 +47,20 @@ export default {
}
}
},
removeListFromNamespaceById(state, list) {
for (const n in state.namespaces) {
// We don't have the namespace id on the list which means we need to loop over all lists until we find it.
// FIXME: Not ideal at all - we should fix that at the api level.
if (state.namespaces[n].id === list.namespaceId) {
for (const l in state.namespaces[n].lists) {
if (state.namespaces[n].lists[l].id === list.id) {
state.namespaces[n].lists.splice(l, 1)
return
}
}
}
}
},
},
getters: {
getListAndNamespaceById: state => listId => {
@ -99,5 +115,11 @@ export default {
return ctx.dispatch('loadNamespaces')
}
},
removeFavoritesNamespaceIfEmpty(ctx) {
if (ctx.state.namespaces[0].id === -2 && ctx.state.namespaces[0].lists.length === 0) {
ctx.state.namespaces.splice(0, 1)
return Promise.resolve()
}
},
},
}