Skip to content

Commit 3333c94

Browse files
author
Guillaume Chau
committed
feat(ui): FolderExplorer
1 parent 1751ca1 commit 3333c94

14 files changed

+210
-3
lines changed

packages/@vue/cli-ui/src/App.vue

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
<router-view/>
44
</div>
55
</template>
6+
7+
<style lang="stylus">
8+
@import "~@vue/ui/dist/vue-ui.css"
9+
10+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template>
2+
<div class="folder-explorer">
3+
<div class="toolbar">
4+
<VueButton
5+
class="icon-button"
6+
icon-left="keyboard_arrow_up"
7+
@click="openParentFolder"
8+
/>
9+
10+
<ApolloQuery
11+
:query="require('@/graphql/cwd.gql')"
12+
class="current-path"
13+
>
14+
<ApolloSubscribeToMore
15+
:document="require('@/graphql/cwdChanged.gql')"
16+
:update-query="cwdChangedUpdate"
17+
/>
18+
19+
<template slot-scope="{ result: { data } }">
20+
<span v-if="data">{{ data.cwd }}</span>
21+
</template>
22+
</ApolloQuery>
23+
</div>
24+
25+
<ApolloQuery
26+
:query="require('@/graphql/folderCurrent.gql')"
27+
class="folders"
28+
>
29+
<template slot-scope="{ result: { data } }">
30+
<template v-if="data">
31+
<FolderExplorerItem
32+
v-for="folder of data.folderCurrent.children"
33+
:key="folder.name"
34+
:folder="folder"
35+
@click.native="openFolder(folder)"
36+
/>
37+
</template>
38+
</template>
39+
</ApolloQuery>
40+
</div>
41+
</template>
42+
43+
<script>
44+
import FolderExplorerItem from './FolderExplorerItem'
45+
import FOLDER_OPEN from '@/graphql/folderOpen.gql'
46+
import FOLDER_OPEN_PARENT from '@/graphql/folderOpenParent.gql'
47+
import FOLDER_CURRENT from '@/graphql/folderCurrent.gql'
48+
49+
export default {
50+
components: {
51+
FolderExplorerItem,
52+
},
53+
54+
methods: {
55+
openFolder (folder) {
56+
this.$apollo.mutate({
57+
mutation: FOLDER_OPEN,
58+
variables: {
59+
path: folder.path
60+
},
61+
update: (store, { data: { folderOpen } }) => {
62+
store.writeQuery({ query: FOLDER_CURRENT, data: { folderCurrent: folderOpen } })
63+
}
64+
})
65+
},
66+
67+
openParentFolder (folder) {
68+
this.$apollo.mutate({
69+
mutation: FOLDER_OPEN_PARENT,
70+
update: (store, { data: { folderOpenParent } }) => {
71+
store.writeQuery({ query: FOLDER_CURRENT, data: { folderCurrent: folderOpenParent } })
72+
}
73+
})
74+
},
75+
76+
cwdChangedUpdate (previousResult, { subscriptionData }) {
77+
return {
78+
cwd: subscriptionData.data.cwd
79+
}
80+
}
81+
}
82+
}
83+
</script>
84+
85+
<style lang="stylus" scoped>
86+
@import "~@/style/imports"
87+
88+
.toolbar
89+
padding 12px
90+
background rgba($vue-color-light-neutral, .2)
91+
h-box()
92+
align-items center
93+
94+
.current-path
95+
flex 100% 1 1
96+
ellipsis()
97+
margin-left 12px
98+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<div class="foder-explorer-item">
3+
<VueIcon icon="folder" class="folder-icon big"/>
4+
<div class="folder-name">{{ folder.name }}</div>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
props: {
11+
folder: {
12+
type: Object,
13+
required: true
14+
}
15+
}
16+
}
17+
</script>
18+
19+
<style lang="stylus" scoped>
20+
@import "~@/style/imports"
21+
22+
.folder-icon
23+
margin 0 4px
24+
>>> svg
25+
fill $vue-color-primary
26+
27+
.folder-name
28+
flex 100% 1 1
29+
margin-left 12px
30+
ellipsis()
31+
32+
.foder-explorer-item
33+
padding 12px
34+
h-box()
35+
align-items center
36+
user-select none
37+
cursor pointer
38+
39+
&:hover
40+
background rgba($vue-color-primary, .1)
41+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let currentProject = null
2+
3+
function list (context) {
4+
return context.db.get('projects').value()
5+
}
6+
7+
function getCurrent (context) {
8+
return currentProject
9+
}
10+
11+
module.exports = {
12+
list,
13+
getCurrent
14+
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const channels = require('./channels')
22
const cwd = require('./connectors/cwd')
33
const folders = require('./connectors/folders')
4+
const projects = require('./connectors/projects')
45

56
module.exports = {
67
Folder: {
@@ -9,7 +10,9 @@ module.exports = {
910

1011
Query: {
1112
cwd: () => cwd.get(),
12-
folderCurrent: (root, args, context) => folders.getCurrent(args, context)
13+
folderCurrent: (root, args, context) => folders.getCurrent(args, context),
14+
projects: (root, args, context) => projects.list(context),
15+
projectCurrent: (root, args, context) => projects.getCurrent(context)
1316
},
1417

1518
Mutation: {
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
cwd
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
subscription {
2+
cwd: cwdChanged
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
folderCurrent {
3+
name
4+
path
5+
children {
6+
name
7+
path
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation ($path: String!) {
2+
folderOpen(path: $path) {
3+
name
4+
path
5+
children {
6+
name
7+
path
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mutation {
2+
folderOpenParent {
3+
name
4+
path
5+
children {
6+
name
7+
path
8+
}
9+
}
10+
}

packages/@vue/cli-ui/src/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import App from './App.vue'
33
import router from './router'
44
import store from './store'
55
import { apolloProvider } from './vue-apollo'
6+
import VueUi from '@vue/ui'
7+
8+
Vue.use(VueUi)
69

710
Vue.config.productionTip = false
811

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "~@vue/ui/src/style/imports"

packages/@vue/cli-ui/src/style/main.styl

Whitespace-only changes.
+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<template>
22
<div class="home">
3-
3+
<FolderExplorer/>
44
</div>
55
</template>
66

77
<script>
8+
import FolderExplorer from '../components/FolderExplorer'
9+
810
export default {
9-
name: 'home'
11+
name: 'home',
12+
13+
components: {
14+
FolderExplorer
15+
}
1016
}
1117
</script>

0 commit comments

Comments
 (0)