Category.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class='route_container'>
  3. <div class='thread_sorting'>
  4. <div>
  5. <select-button style='margin-right: 1rem' v-model='selectedCategory' :options='categories'></select-button>
  6. <select-options :options='filterOptions' v-model='selectedFilterOption'></select-options>
  7. </div>
  8. <button class='button' @click='$router.push("/thread/new")'>Post new thread</button>
  9. </div>
  10. <table class='threads'>
  11. <colgroup>
  12. <col span="1" style="width: 50%;">
  13. <col span="1" style="width: 22.5%;">
  14. <col span="1" style="width: 22.5%;">
  15. <col span="1" style="width: 5%;">
  16. </colgroup>
  17. <thead>
  18. <tr class='thread thread--header'>
  19. <th>Title</th>
  20. <th>Latest post</th>
  21. <th>Category</th>
  22. <th>Replies</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr class='thread' v-for='thread in filteredThreads' @click='navigateToThread(thread.slug, thread.id)'>
  27. <td>{{thread.title}}</td>
  28. <td>
  29. <div>{{thread.latestPostUser}}</div>
  30. <div>{{thread.latestPostDate | formatDate('time|date', ' - ') }}</div>
  31. </td>
  32. <td>{{thread.category}}</td>
  33. <td>{{thread.replies}}</td>
  34. </tr>
  35. <tr class='thread' v-if='!filteredThreads.length' colspan='4'>
  36. <td colspan='4' class='thread--empty'>No threads or posts.</td>
  37. </tr>
  38. </tbody>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import SelectButton from '../SelectButton'
  44. import TabView from '../TabView'
  45. import SelectOptions from '../SelectOptions'
  46. export default {
  47. name: 'index',
  48. components: {
  49. SelectButton,
  50. TabView,
  51. SelectOptions
  52. },
  53. data () {
  54. return {
  55. filterOptions: [
  56. {name: 'New', value: 'NEW'},
  57. {name: 'Most active', value: 'MOST_ACTIVE'},
  58. {name: 'No replies', value: 'NO_REPLIES'}
  59. ],
  60. selectedFilterOption: 'NEW',
  61. selectedCategory: this.$route.params.category.toUpperCase(),
  62. threads: [
  63. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 30, id: 1, slug: 'test'},
  64. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
  65. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
  66. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
  67. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
  68. {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'},
  69. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
  70. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
  71. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
  72. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
  73. {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'},
  74. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
  75. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
  76. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
  77. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
  78. {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'},
  79. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
  80. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
  81. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
  82. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
  83. {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'},
  84. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
  85. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
  86. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
  87. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
  88. {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'},
  89. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'TECHNOLOGY', replies: 10, id: 1, slug: 'test'},
  90. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'FOOD', replies: 5, id: 1, slug: 'test'},
  91. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 23, id: 1, slug: 'test'},
  92. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'PROGRAMMING', replies: 40, id: 1, slug: 'test'},
  93. {title: 'example title', latestPostUser: 'user', latestPostDate: new Date(), category: 'BOOKS', replies: 0, id: 1, slug: 'test'}
  94. ]
  95. }
  96. },
  97. computed: {
  98. filteredThreads () {
  99. var categories = {};
  100. var filter = this.selectedFilterOption
  101. this.$store.state.meta.categories.forEach(category => {
  102. categories[category.value] = category.name;
  103. });
  104. return this.threads.filter(thread => {
  105. return (thread.category === this.selectedCategory) || (this.selectedCategory === 'ALL');
  106. }).map(thread => {
  107. var _thread = Object.assign({}, thread);
  108. _thread.category = categories[thread.category];
  109. return _thread;
  110. }).sort((a, b) => {
  111. if(filter === 'NEW') {
  112. return a.latestPostDate - b.latestPostDate;
  113. } else if(filter === 'MOST_ACTIVE') {
  114. return b.replies - a.replies;
  115. }
  116. }).filter(thread => {
  117. if(filter === 'NO_REPLIES') {
  118. return !thread.replies;
  119. } else {
  120. return true;
  121. }
  122. });
  123. },
  124. categories () {
  125. return this.$store.state.meta.categories
  126. }
  127. },
  128. methods: {
  129. navigateToThread (slug, id) {
  130. this.$router.push('/thread/' + slug + '/' + id);
  131. }
  132. },
  133. watch: {
  134. selectedCategory (newValue) {
  135. this.$router.push('/category/' + newValue.toLowerCase());
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang='scss' scoped>
  141. @import '../../assets/scss/variables.scss';
  142. .thread_sorting {
  143. margin-bottom: 1rem;
  144. display: flex;
  145. justify-content: space-between;
  146. }
  147. .threads {
  148. border-collapse: collapse;
  149. }
  150. .thread {
  151. background-color: #fff;
  152. padding: 0.5rem 0;
  153. cursor: default;
  154. text-align: left;
  155. transition: background-color 0.2s;
  156. &:hover {
  157. background-color: $color__lightgray--primary;
  158. }
  159. td, th {
  160. padding: 0.3rem 0.5rem;
  161. border-bottom: solid thin $color__lightgray--primary;
  162. }
  163. @at-root #{&}--header {
  164. &:hover {
  165. background-color: #fff;
  166. }
  167. th {
  168. font-weight: 400;
  169. padding-bottom: 0.25rem;
  170. border-bottom: thin solid $color__lightgray--darkest;
  171. }
  172. }
  173. @at-root #{&}--empty {
  174. height: 5rem;
  175. text-align: center;
  176. font-size: 2rem;
  177. user-select: none;
  178. cursor: default;
  179. transition: none;
  180. &:hover {
  181. transition: none;
  182. background-color: #fff;
  183. }
  184. }
  185. @at-root #{&}__section {
  186. padding: 0 0.5rem;
  187. }
  188. @at-root #{&}__user {
  189. display: inline-block;
  190. }
  191. @at-root #{&}__date {
  192. color: $color__text--secondary;
  193. display: inline-block;
  194. }
  195. }
  196. </style>