Skip to content

Commit 96ab5e8

Browse files
committed
added support for collections
1 parent d8456b6 commit 96ab5e8

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

src/components/documents.vue

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<h3 style="margin-top: 0;">Your Collections: </h3>
88
<button @click="newCollection" class="button warning full-width">New Collection</button>
99
</div>
10-
<a @click="filterBy(collection)" class="collection collection-link" v-for="collection in collections" :key="collection.key">
10+
<div @click="filterBy(collection)" v-bind:class="{selected: collection.key == collectionFilter }" class="collection" v-for="collection in collections" :key="collection.key">
1111
<hr class="collection-rule">
1212
<div class="fab-container">
13-
<h5>{{collection.name}}</h5>
13+
<h5>{{collection.name}}</h5>
1414
</div>
15-
</a>
15+
</div>
1616

1717

1818
</div>
@@ -137,6 +137,7 @@ export default {
137137
let docKey = doc.key;
138138
let utc = doc.val().utc;
139139
let lastOpened = doc.val().lastOpened;
140+
let collections = doc.val().collections;
140141
//console.log(utc, lastOpened, docKey);
141142
db
142143
.ref(`documentMeta/${doc.val().uid}/${doc.val().docId}`)
@@ -146,7 +147,8 @@ export default {
146147
this.docs.unshift({
147148
doc: docMeta.val(),
148149
key: docKey,
149-
uid: doc.val().uid
150+
uid: doc.val().uid,
151+
collections: collections
150152
});
151153
152154
// ...
@@ -195,7 +197,16 @@ export default {
195197
filterSearch() {
196198
let query = this.search.toLowerCase();
197199
let result = this.sortedDocs;
198-
200+
if (this.collectionFilter) {
201+
const collectionFilter = doc => {
202+
if (doc.collections) {
203+
if (doc.collections[this.collectionFilter]) {
204+
return true;
205+
}
206+
}
207+
};
208+
result = result.filter(collectionFilter);
209+
}
199210
if (!query) {
200211
return result;
201212
} else {
@@ -206,16 +217,18 @@ export default {
206217
.includes(query);
207218
}
208219
};
209-
if (this.collectionFilter) {
210-
} else {
211-
return result.filter(filter);
212-
}
220+
221+
return result.filter(filter);
213222
}
214223
}
215224
},
216225
methods: {
217226
filterBy(collection) {
218-
this.collectionFilter = collection.key;
227+
if (this.collectionFilter == collection.key) {
228+
this.collectionFilter = false;
229+
} else {
230+
this.collectionFilter = collection.key;
231+
}
219232
},
220233
addDocToCollection() {
221234
let docId = this.addDoc.userData.key;

0 commit comments

Comments
 (0)