1
1
<template >
2
- <div class =" folder-explorer" >
2
+ <div
3
+ class =" folder-explorer"
4
+ :class =" {
5
+ error
6
+ }"
7
+ >
3
8
<div class =" toolbar" >
4
9
<VueButton
5
10
class =" icon-button"
6
11
icon-left =" keyboard_arrow_up"
12
+ v-tooltip =" 'Open parent folder'"
7
13
@click =" openParentFolder"
8
14
/>
9
15
16
+ <div v-if =" editingPath" class =" path-edit" >
17
+ <VueInput
18
+ ref =" pathInput"
19
+ v-model =" editedPath"
20
+ placeholder =" Enter the full path to a folder"
21
+ icon-left =" edit"
22
+ @keyup.esc =" editingPath = false"
23
+ @keyup.enter =" submitPathEdit()"
24
+ />
25
+ </div >
26
+
10
27
<ApolloQuery
28
+ v-else
29
+ ref =" cwd"
11
30
:query =" require('@/graphql/cwd.gql')"
12
31
class =" current-path"
32
+ v-tooltip =" 'Edit path'"
33
+ @click.native =" openPathEdit()"
13
34
>
14
35
<ApolloSubscribeToMore
15
36
:document =" require('@/graphql/cwdChanged.gql')"
20
41
<span v-if =" data" >{{ data.cwd }}</span >
21
42
</template >
22
43
</ApolloQuery >
44
+
45
+ <VueIcon
46
+ v-if =" error"
47
+ icon =" error"
48
+ class =" error-icon big"
49
+ />
50
+
51
+ <VueButton
52
+ class =" icon-button"
53
+ icon-left =" refresh"
54
+ v-tooltip =" 'Refresh'"
55
+ @click =" refreshFolder"
56
+ />
23
57
</div >
24
58
25
59
<ApolloQuery
32
66
v-for =" folder of data.folderCurrent.children"
33
67
:key =" folder.name"
34
68
:folder =" folder"
35
- @click.native =" openFolder(folder)"
69
+ @click.native =" openFolder(folder.path )"
36
70
/>
37
71
</template >
38
72
</template >
@@ -51,32 +85,67 @@ export default {
51
85
FolderExplorerItem,
52
86
},
53
87
88
+ data () {
89
+ return {
90
+ error: false ,
91
+ editingPath: false ,
92
+ editedPath: ' ' ,
93
+ }
94
+ },
95
+
54
96
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
- })
97
+ async openFolder (path ) {
98
+ this .editingPath = false
99
+ this .error = false
100
+ try {
101
+ await this .$apollo .mutate ({
102
+ mutation: FOLDER_OPEN ,
103
+ variables: {
104
+ path
105
+ },
106
+ update : (store , { data: { folderOpen } }) => {
107
+ store .writeQuery ({ query: FOLDER_CURRENT , data: { folderCurrent: folderOpen } })
108
+ }
109
+ })
110
+ } catch (e) {
111
+ this .error = true
112
+ }
65
113
},
66
114
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
- })
115
+ async openParentFolder (folder ) {
116
+ this .editingPath = false
117
+ this .error = false
118
+ try {
119
+ await this .$apollo .mutate ({
120
+ mutation: FOLDER_OPEN_PARENT ,
121
+ update : (store , { data: { folderOpenParent } }) => {
122
+ store .writeQuery ({ query: FOLDER_CURRENT , data: { folderCurrent: folderOpenParent } })
123
+ }
124
+ })
125
+ } catch (e) {
126
+ this .error = true
127
+ }
74
128
},
75
129
76
130
cwdChangedUpdate (previousResult , { subscriptionData }) {
77
131
return {
78
132
cwd: subscriptionData .data .cwd
79
133
}
134
+ },
135
+
136
+ async openPathEdit () {
137
+ this .editedPath = this .$refs .cwd .result .data .cwd
138
+ this .editingPath = true
139
+ await this .$nextTick ()
140
+ this .$refs .pathInput .focus ()
141
+ },
142
+
143
+ submitPathEdit () {
144
+ this .openFolder (this .editedPath )
145
+ },
146
+
147
+ refreshFolder () {
148
+ this .openFolder (this .$refs .cwd .result .data .cwd )
80
149
}
81
150
}
82
151
}
@@ -91,8 +160,25 @@ export default {
91
160
h-box ()
92
161
align-items center
93
162
163
+ >>> > *
164
+ space-between-x (12px )
165
+
94
166
.current-path
95
167
flex 100% 1 1
96
168
ellipsis ()
97
- margin-left 12px
169
+ cursor pointer
170
+
171
+ .path-edit
172
+ flex 100% 1 1
173
+ > .vue-input
174
+ width 100%
175
+
176
+ .error-icon
177
+ >>> svg
178
+ fill $vue-color-danger
179
+
180
+ .folder-explorer
181
+ & .error
182
+ .current-path
183
+ color $vue-color-danger
98
184
</style >
0 commit comments