Skip to content

Commit 653cc30

Browse files
author
Guillaume Chau
committed
feat(ui): toggle favorite in top bar
1 parent 0872781 commit 653cc30

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@
148148
}
149149
},
150150
"top-bar": {
151-
"no-favorites": "No favorite projects"
151+
"no-favorites": "No favorite projects",
152+
"favorite-projects": "Favorite projects"
152153
},
153154
"view-badge": {
154155
"labels": {

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,35 @@
77
icon-right="arrow_drop_down"
88
button-class="flat round"
99
>
10-
<VueDropdownButton
11-
v-for="project of favoriteProjects"
12-
:key="project.id"
13-
:label="project.name"
14-
icon-left="star"
15-
@click="openProject(project)"
16-
/>
10+
<template v-if="projectCurrent">
11+
<VueSwitch
12+
:value="projectCurrent.favorite"
13+
:icon="projectCurrent.favorite ? 'star' : 'star_border'"
14+
class="extend-left"
15+
@input="toggleCurrentFavorite()"
16+
>
17+
{{ $t('org.vue.components.project-select-list-item.tooltips.favorite') }}
18+
</VueSwitch>
19+
</template>
20+
21+
<div class="dropdown-separator"/>
1722

1823
<div v-if="!favoriteProjects.length" class="vue-ui-empty">{{ $t('org.vue.components.top-bar.no-favorites') }}</div>
1924

25+
<template v-else>
26+
<div class="section-title">
27+
{{ $t('org.vue.components.top-bar.favorite-projects') }}
28+
</div>
29+
30+
<VueDropdownButton
31+
v-for="project of favoriteProjects"
32+
:key="project.id"
33+
:label="project.name"
34+
icon-left="star"
35+
@click="openProject(project)"
36+
/>
37+
</template>
38+
2039
<div class="dropdown-separator"/>
2140

2241
<VueDropdownButton
@@ -44,6 +63,7 @@ import { resetApollo } from '../vue-apollo'
4463
import PROJECT_CURRENT from '../graphql/projectCurrent.gql'
4564
import PROJECTS from '../graphql/projects.gql'
4665
import PROJECT_OPEN from '../graphql/projectOpen.gql'
66+
import PROJECT_SET_FAVORITE from '../graphql/projectSetFavorite.gql'
4767
4868
export default {
4969
apollo: {
@@ -72,6 +92,18 @@ export default {
7292
})
7393
7494
await resetApollo()
95+
},
96+
97+
async toggleCurrentFavorite () {
98+
if (this.projectCurrent) {
99+
await this.$apollo.mutate({
100+
mutation: PROJECT_SET_FAVORITE,
101+
variables: {
102+
id: this.projectCurrent.id,
103+
favorite: this.projectCurrent.favorite ? 0 : 1
104+
}
105+
})
106+
}
75107
}
76108
}
77109
}

0 commit comments

Comments
 (0)