Skip to content

Commit

Permalink
feat(ui): toggle favorite in top bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jul 1, 2018
1 parent 0872781 commit 653cc30
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/locales/en.json
Expand Up @@ -148,7 +148,8 @@
}
},
"top-bar": {
"no-favorites": "No favorite projects"
"no-favorites": "No favorite projects",
"favorite-projects": "Favorite projects"
},
"view-badge": {
"labels": {
Expand Down
46 changes: 39 additions & 7 deletions packages/@vue/cli-ui/src/components/TopBar.vue
Expand Up @@ -7,16 +7,35 @@
icon-right="arrow_drop_down"
button-class="flat round"
>
<VueDropdownButton
v-for="project of favoriteProjects"
:key="project.id"
:label="project.name"
icon-left="star"
@click="openProject(project)"
/>
<template v-if="projectCurrent">
<VueSwitch
:value="projectCurrent.favorite"
:icon="projectCurrent.favorite ? 'star' : 'star_border'"
class="extend-left"
@input="toggleCurrentFavorite()"
>
{{ $t('org.vue.components.project-select-list-item.tooltips.favorite') }}
</VueSwitch>
</template>

<div class="dropdown-separator"/>

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

<template v-else>
<div class="section-title">
{{ $t('org.vue.components.top-bar.favorite-projects') }}
</div>

<VueDropdownButton
v-for="project of favoriteProjects"
:key="project.id"
:label="project.name"
icon-left="star"
@click="openProject(project)"
/>
</template>

<div class="dropdown-separator"/>

<VueDropdownButton
Expand Down Expand Up @@ -44,6 +63,7 @@ import { resetApollo } from '../vue-apollo'
import PROJECT_CURRENT from '../graphql/projectCurrent.gql'
import PROJECTS from '../graphql/projects.gql'
import PROJECT_OPEN from '../graphql/projectOpen.gql'
import PROJECT_SET_FAVORITE from '../graphql/projectSetFavorite.gql'
export default {
apollo: {
Expand Down Expand Up @@ -72,6 +92,18 @@ export default {
})
await resetApollo()
},
async toggleCurrentFavorite () {
if (this.projectCurrent) {
await this.$apollo.mutate({
mutation: PROJECT_SET_FAVORITE,
variables: {
id: this.projectCurrent.id,
favorite: this.projectCurrent.favorite ? 0 : 1
}
})
}
}
}
}
Expand Down

0 comments on commit 653cc30

Please sign in to comment.