Skip to content

Commit 120c13d

Browse files
author
Guillaume Chau
committed
feat(ui): favorite projects
1 parent 7571e80 commit 120c13d

File tree

8 files changed

+91
-12
lines changed

8 files changed

+91
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
export default {
3+
functional: true,
4+
5+
render (h, { props, data }) {
6+
return h('div', data.scopedSlots.default({ list: props.list.filter(props.filter) }))
7+
}
8+
}
9+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
export default {
3+
functional: true,
4+
5+
render (h, { props, data }) {
6+
return h('div', data.scopedSlots.default({ list: props.list.slice().sort(props.compare) }))
7+
}
8+
}
9+
</script>

packages/@vue/cli-ui/src/components/ProjectSelectList.vue

+43-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,37 @@
77
<template slot-scope="{ result: { data } }">
88
<template v-if="data">
99
<div v-if="data.projects.length">
10-
<ProjectSelectListItem
11-
v-for="project of data.projects"
12-
:key="project.id"
13-
:project="project"
14-
@click.native="openProject(project)"
15-
@remove="removeProject(project)"
16-
@favorite="toggleFavorite(project)"
17-
/>
10+
<ListFilter
11+
v-for="favorite of [true, false]"
12+
:key="favorite"
13+
:list="data.projects"
14+
:filter="item => !!item.favorite === favorite"
15+
>
16+
<template slot-scope="{ list }">
17+
<div
18+
v-if="data.projects.find(item => item.favorite)"
19+
class="cta-text"
20+
>
21+
{{ $t(`components.project-select-list.titles.${favorite ? 'favorite' : 'other'}`) }}
22+
</div>
23+
24+
<ListSort
25+
:list="list"
26+
:compare="compareProjects"
27+
>
28+
<template slot-scope="{ list }">
29+
<ProjectSelectListItem
30+
v-for="project of list"
31+
:key="project.id"
32+
:project="project"
33+
@click.native="openProject(project)"
34+
@remove="removeProject(project)"
35+
@favorite="toggleFavorite(project)"
36+
/>
37+
</template>
38+
</ListSort>
39+
</template>
40+
</ListFilter>
1841
</div>
1942
<div v-else class="vue-ui-empty">
2043
<VueIcon icon="attach_file" class="empty-icon"/>
@@ -30,6 +53,7 @@
3053
import PROJECTS from '../graphql/projects.gql'
3154
import PROJECT_OPEN from '../graphql/projectOpen.gql'
3255
import PROJECT_REMOVE from '../graphql/projectRemove.gql'
56+
import PROJECT_SET_FAVORITE from '../graphql/projectSetFavorite.gql'
3357
3458
export default {
3559
methods: {
@@ -62,7 +86,17 @@ export default {
6286
},
6387
6488
async toggleFavorite (project) {
65-
// TODO
89+
await this.$apollo.mutate({
90+
mutation: PROJECT_SET_FAVORITE,
91+
variables: {
92+
id: project.id,
93+
favorite: project.favorite ? 0 : 1
94+
}
95+
})
96+
},
97+
98+
compareProjects (a, b) {
99+
return a.name.localeCompare(b.name)
66100
}
67101
}
68102
}

packages/@vue/cli-ui/src/graphql-api/connectors/projects.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ function resetCwd (context) {
325325
}
326326
}
327327

328+
function findOne (id, context) {
329+
return context.db.get('projects').find({ id }).value()
330+
}
331+
332+
function setFavorite ({ id, favorite }, context) {
333+
context.db.get('projects').find({ id }).assign({ favorite }).write()
334+
335+
return findOne(id, context)
336+
}
337+
328338
module.exports = {
329339
list,
330340
getCurrent,
@@ -336,5 +346,6 @@ module.exports = {
336346
import: importProject,
337347
open,
338348
remove,
339-
resetCwd
349+
resetCwd,
350+
setFavorite
340351
}

packages/@vue/cli-ui/src/graphql-api/resolvers.js

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module.exports = {
6363
projectOpen: (root, { id }, context) => projects.open(id, context),
6464
projectRemove: (root, { id }, context) => projects.remove(id, context),
6565
projectCwdReset: (root, args, context) => projects.resetCwd(context),
66+
projectSetFavorite: (root, args, context) => projects.setFavorite(args, context),
6667
pluginInstall: (root, { id }, context) => plugins.install(id, context),
6768
pluginUninstall: (root, { id }, context) => plugins.uninstall(id, context),
6869
pluginInvoke: (root, { id }, context) => plugins.runInvoke(id, context),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import "./projectFragment.gql"
2+
3+
mutation projectSetFavorite ($id: ID!, $favorite: Int!) {
4+
projectSetFavorite (id: $id, favorite: $favorite) {
5+
...project
6+
}
7+
}

packages/@vue/cli-ui/src/locales/en.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
}
3737
},
3838
"project-select-list": {
39-
"empty": "No existing projects"
39+
"empty": "No existing projects",
40+
"titles": {
41+
"favorite": "Favorite projects",
42+
"other": "Other projects"
43+
}
4044
},
4145
"project-select-list-item": {
4246
"tooltips": {

packages/@vue/cli-ui/src/locales/fr.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
}
3737
},
3838
"project-select-list": {
39-
"empty": "Aucun projet"
39+
"empty": "Aucun projet",
40+
"titles": {
41+
"favorite": "Projets favoris",
42+
"other": "Autres projets"
43+
}
4044
},
4145
"project-select-list-item": {
4246
"tooltips": {

0 commit comments

Comments
 (0)