|
@@ -3,7 +3,7 @@
|
|
|
<div class='thread_sorting'>
|
|
|
<div>
|
|
|
<select-button style='margin-right: 1rem' v-model='selectedCategory' :options='categories'></select-button>
|
|
|
- <select-options :options='options' name='filterOptions'></select-options>
|
|
|
+ <select-options :options='filterOptions' v-model='selectedFilterOption'></select-options>
|
|
|
</div>
|
|
|
<button class='button' @click='$router.push("/thread/new")'>Post new thread</button>
|
|
|
</div>
|
|
@@ -23,7 +23,7 @@
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
- <tr class='thread' v-for='thread in threads' @click='navigateToThread(thread.slug, thread.id)'>
|
|
|
+ <tr class='thread' v-for='thread in filteredThreads' @click='navigateToThread(thread.slug, thread.id)'>
|
|
|
<td>{{thread.title}}</td>
|
|
|
<td>
|
|
|
<div>{{thread.latestPostUser}}</div>
|
|
@@ -32,7 +32,7 @@
|
|
|
<td>{{thread.category}}</td>
|
|
|
<td>{{thread.replies}}</td>
|
|
|
</tr>
|
|
|
- <tr class='thread' v-if='!threads.length' colspan='4'>
|
|
|
+ <tr class='thread' v-if='!filteredThreads.length' colspan='4'>
|
|
|
<td colspan='4' class='thread--empty'>No threads or posts.</td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
@@ -54,28 +54,81 @@
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
- options: [
|
|
|
+ filterOptions: [
|
|
|
{name: 'New', value: 'NEW'},
|
|
|
{name: 'Most active', value: 'MOST_ACTIVE'},
|
|
|
{name: 'No replies', value: 'NO_REPLIES'}
|
|
|
],
|
|
|
- selected: null
|
|
|
+ selectedFilterOption: 'NEW',
|
|
|
+ selectedCategory: this.$route.params.category.toUpperCase(),
|
|
|
+ threads: [
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'},{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'},{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'},{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'},{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'},{title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
|
|
|
+ {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'}
|
|
|
+
|
|
|
+ ]
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- threads () {
|
|
|
- return this.$store.getters.filteredThreads;
|
|
|
+ filteredThreads () {
|
|
|
+ var categories = {};
|
|
|
+ var filter = this.selectedFilterOption
|
|
|
+
|
|
|
+ this.$store.state.meta.categories.forEach(category => {
|
|
|
+ categories[category.value] = category.name;
|
|
|
+ });
|
|
|
+
|
|
|
+ return this.threads.filter(thread => {
|
|
|
+ return (thread.category === this.selectedCategory) || (this.selectedCategory === 'ALL');
|
|
|
+ }).map(thread => {
|
|
|
+ var _thread = Object.assign({}, thread);
|
|
|
+ _thread.category = categories[thread.category];
|
|
|
+
|
|
|
+ return _thread;
|
|
|
+ }).sort((a, b) => {
|
|
|
+ if(filter === 'NEW') {
|
|
|
+ return a.latestPostDate - b.latestPostDate;
|
|
|
+ } else if(filter === 'MOST_ACTIVE') {
|
|
|
+ return b.replies - a.replies;
|
|
|
+ }
|
|
|
+ }).filter(thread => {
|
|
|
+ if(filter === 'NO_REPLIES') {
|
|
|
+ return !thread.replies;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
categories () {
|
|
|
return this.$store.state.meta.categories
|
|
|
- },
|
|
|
- selectedCategory: {
|
|
|
- get () {
|
|
|
- return this.$store.state.category.selectedCategory;
|
|
|
- },
|
|
|
- set (category) {
|
|
|
- this.$store.commit('selectCategory', category);
|
|
|
- }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
@@ -87,9 +140,6 @@
|
|
|
selectedCategory (newValue) {
|
|
|
this.$router.push('/category/' + newValue.toLowerCase());
|
|
|
}
|
|
|
- },
|
|
|
- mounted () {
|
|
|
- this.selectedCategory = this.$route.params.category.toUpperCase();
|
|
|
}
|
|
|
}
|
|
|
</script>
|