MoreThreads.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class='more_threads'>
  3. <div class='more_threads__header'>More threads in category '{{category.name}}'</div>
  4. <div class='more_threads__empty overlay_message' v-if='empty'>
  5. No more threads to show
  6. </div>
  7. <template v-else>
  8. <div class='more_threads__thread more_threads__thread--header'>
  9. <div class='more_threads__name'>Thread</div>
  10. <div class='more_threads__date_created'>Date created</div>
  11. </div>
  12. <div class='more_threads__thread' v-for='thread in threads' @click='goToThread(thread)'>
  13. <div class='more_threads__name' >{{thread.name}}</div>
  14. <div class='more_threads__date_created'>{{ thread.createdAt | formatDate }}</div>
  15. </div>
  16. </template>
  17. </div>
  18. </template>
  19. <script>
  20. import AjaxErrorHandler from '../assets/js/errorHandler'
  21. export default {
  22. name: 'MoreThreads',
  23. props: ['category', 'threadId'],
  24. data () {
  25. return { threads: [], empty: false }
  26. },
  27. methods: {
  28. goToThread (thread) {
  29. this.$router.push(`/thread/${thread.slug}/${thread.id}`)
  30. }
  31. },
  32. mounted () {
  33. this.axios
  34. .get('/api/v1/category/' + this.category.value)
  35. .then(res => {
  36. let filtered = res.data.Threads.filter(thread => {
  37. return thread.id !== this.threadId
  38. })
  39. this.threads = filtered.slice(0, 4)
  40. this.empty = !filtered.length
  41. })
  42. .catch(AjaxErrorHandler(this.$store))
  43. }
  44. }
  45. </script>
  46. <style lang='scss' scoped>
  47. @import '../assets/scss/variables.scss';
  48. .more_threads {
  49. background-color: #fff;
  50. border-radius: 0.25rem;
  51. width: 80%;
  52. padding: 1rem;
  53. margin-top: 1.5rem;
  54. @at-root #{&}__header {
  55. font-size: 1.5rem;
  56. font-weight: 500;
  57. padding-left: 0.25rem;
  58. }
  59. @at-root #{&}__thread {
  60. display: flex;
  61. justify-content: space-between;
  62. font-size: 1rem;
  63. cursor: pointer;
  64. padding: 0.6rem;
  65. align-items: center;
  66. border-bottom: thin solid $color__gray--darker;
  67. transition: all 0.2s;
  68. &:hover {
  69. background-color: $color__lightgray--primary;
  70. }
  71. &:active {
  72. background-color: $color__lightgray--darker;
  73. }
  74. @at-root #{&}--header {
  75. cursor: default;
  76. font-size: 1rem;
  77. font-weight: 500;
  78. border-bottom: 0.125rem solid $color__gray--darker;
  79. &:hover { background-color: #fff; }
  80. }
  81. }
  82. @at-root #{&}__date_created {
  83. color: $color__text--secondary;
  84. font-size: 1rem;
  85. }
  86. @at-root #{&}__empty {
  87. padding: 1rem;
  88. font-size: 1.5rem;
  89. }
  90. }
  91. @media (max-width: 420px) {
  92. .more_threads {
  93. width: 100%;
  94. margin-bottom: -6.5rem;
  95. @at-root #{&}__empty {
  96. margin-top: 0;
  97. }
  98. }
  99. }
  100. </style>