Index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class='route_container'>
  3. <div class='thread_sorting'>
  4. <select-options
  5. :options='filterOptions'
  6. v-model='selectedFilterOption'
  7. class='thread_sorting__filter'
  8. ></select-options>
  9. <button class='button' v-if='this.$store.state.username' @click='$router.push("/thread/new")'>Post new thread</button>
  10. </div>
  11. <div class='threads_main'>
  12. <div class='threads_main__side_bar'>
  13. <div class='threads_main__side_bar__title'>
  14. categories
  15. </div>
  16. <div
  17. v-for='category in categories'
  18. class='threads_main__side_bar__menu_item'
  19. :class='{"threads_main__side_bar__menu_item--selected": category.value === selectedCategory}'
  20. @click='selectedCategory = category.value'
  21. >
  22. <span
  23. class='threads_main__side_bar__menu_item__border'
  24. :style='{"background-color": category.color}'
  25. ></span>
  26. {{category.name}}
  27. </div>
  28. </div>
  29. <div class='threads_main__threads' v-if='filteredThreads.length'>
  30. <thread-display v-for='thread in filteredThreads' :thread='thread'></thread-display>
  31. </div>
  32. <div v-else class='threads_main__threads thread--empty'>No threads or posts.</div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import TabView from '../TabView'
  38. import ThreadDisplay from '../ThreadDisplay'
  39. import SelectOptions from '../SelectOptions'
  40. import AjaxErrorHandler from '../../assets/js/errorHandler'
  41. export default {
  42. name: 'index',
  43. components: {
  44. TabView,
  45. ThreadDisplay,
  46. SelectOptions
  47. },
  48. data () {
  49. return {
  50. filterOptions: [
  51. {name: 'New', value: 'NEW'},
  52. {name: 'Most active', value: 'MOST_ACTIVE'},
  53. {name: 'No replies', value: 'NO_REPLIES'}
  54. ],
  55. selectedFilterOption: 'NEW',
  56. threads: []
  57. }
  58. },
  59. computed: {
  60. filteredThreads () {
  61. var categories = {};
  62. var filter = this.selectedFilterOption
  63. this.$store.state.meta.categories.forEach(category => {
  64. categories[category.value] = category.name;
  65. });
  66. return this.threads.filter(thread => {
  67. return (thread.Category.value === this.selectedCategory) || (this.selectedCategory === 'ALL');
  68. }).map(thread => {
  69. var _thread = Object.assign({}, thread);
  70. _thread.category = categories[thread.Category.value];
  71. return _thread;
  72. }).sort((a, b) => {
  73. if(filter === 'NEW') {
  74. let aDate = new Date(a.Posts[0].createdAt)
  75. let bDate = new Date(b.Posts[0].createdAt)
  76. return bDate - aDate;
  77. } else if(filter === 'MOST_ACTIVE') {
  78. return b.postsCount - a.postsCount;
  79. }
  80. }).filter(thread => {
  81. if(filter === 'NO_REPLIES' && thread.postsCount-1) {
  82. return false
  83. } else {
  84. return true;
  85. }
  86. });
  87. },
  88. categories () {
  89. console.log(this.$store.getters.alphabetizedCategories)
  90. return this.$store.getters.alphabetizedCategories
  91. },
  92. selectedCategory: {
  93. set (val) {
  94. this.$store.commit('setSelectedCategory', val)
  95. },
  96. get () {
  97. return this.$store.state.category.selectedCategory
  98. }
  99. }
  100. },
  101. methods: {
  102. navigateToThread (slug, id) {
  103. this.$router.push('/thread/' + slug + '/' + id);
  104. },
  105. getThreads () {
  106. this.axios
  107. .get('/api/v1/category/' + this.selectedCategory)
  108. .then(res => {
  109. this.threads = res.data.Threads
  110. })
  111. .catch(AjaxErrorHandler(this.$store))
  112. }
  113. },
  114. watch: {
  115. selectedCategory (newValue) {
  116. this.$router.push('/category/' + newValue.toLowerCase());
  117. },
  118. $route () {
  119. this.selectedCategory = this.$route.path.split('/')[2].toUpperCase()
  120. this.getThreads()
  121. }
  122. },
  123. created () {
  124. this.selectedCategory = this.$route.path.split('/')[2].toUpperCase()
  125. this.getThreads()
  126. }
  127. }
  128. </script>
  129. <style lang='scss' scoped>
  130. @import '../../assets/scss/variables.scss';
  131. .threads_main {
  132. display: flex;
  133. }
  134. .thread_sorting {
  135. margin-bottom: 1rem;
  136. display: flex;
  137. justify-content: space-between;
  138. @at-root #{&}__display {
  139. padding-right: 0.5rem;
  140. border-right: thin solid $color__gray--primary;
  141. margin-right: 1.25rem;
  142. width: 10rem;
  143. }
  144. }
  145. .threads_main__side_bar {
  146. width: 10rem;
  147. border-right: thin solid $color__gray--primary;
  148. margin-top: 0.5rem;
  149. @at-root #{&}__title {
  150. cursor: default;
  151. font-weight: 500;
  152. font-variant: small-caps;
  153. font-size: 1.125rem;
  154. }
  155. @at-root #{&}__menu_item {
  156. cursor: pointer;
  157. margin-top: 0.5rem;
  158. position: relative;
  159. #{&}__border {
  160. display: inline-block;
  161. width: 0.2rem;
  162. z-index: 1;
  163. height: 100%;
  164. position: absolute;
  165. left: -0.75rem;
  166. opacity: 0;
  167. top: 0.1rem;
  168. background-color: $color__gray--darkest;
  169. transition: all 0.2s;
  170. }
  171. &:hover #{&}__border {
  172. left: -0.5rem;
  173. opacity: 1;
  174. }
  175. &:active #{&}__border {
  176. filter: brightness(0.8);
  177. }
  178. #{&}--selected {
  179. font-weight: 500;
  180. .threads_main__side_bar__menu_item__border {
  181. opacity: 1;
  182. left: -0.5rem;
  183. &:active {
  184. filter: brightness(1);
  185. }
  186. }
  187. }
  188. }
  189. }
  190. .threads_main__threads {
  191. border-collapse: collapse;
  192. margin-top: 0.25rem;
  193. margin-left: 1rem;
  194. width: calc(100% - 11rem);
  195. }
  196. .thread {
  197. background-color: #fff;
  198. padding: 0.5rem 0;
  199. cursor: default;
  200. text-align: left;
  201. transition: background-color 0.2s;
  202. &:hover {
  203. background-color: $color__lightgray--primary;
  204. }
  205. td, th {
  206. padding: 0.3rem 0.5rem;
  207. border-bottom: solid thin $color__lightgray--primary;
  208. }
  209. @at-root #{&}--header {
  210. &:hover {
  211. background-color: #fff;
  212. }
  213. th {
  214. font-weight: 400;
  215. padding-bottom: 0.25rem;
  216. border-bottom: thin solid $color__lightgray--darkest;
  217. }
  218. }
  219. @at-root #{&}--empty {
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. padding-right: 5rem;
  224. font-size: 2rem;
  225. user-select: none;
  226. cursor: default;
  227. transition: none;
  228. &:hover {
  229. transition: none;
  230. background-color: #fff;
  231. }
  232. }
  233. @at-root #{&}__section {
  234. padding: 0 0.5rem;
  235. }
  236. @at-root #{&}__user {
  237. display: inline-block;
  238. }
  239. @at-root #{&}__date {
  240. color: $color__text--secondary;
  241. display: inline-block;
  242. }
  243. }
  244. </style>