UserThreads.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class='user_threads'>
  3. <div class='user_threads__title'>Threads by {{username}}</div>
  4. <scroll-load
  5. :loading='loadingThreads'
  6. :showNext='nextURL !== null'
  7. @loadNext='loadNewThreads'
  8. v-if='threads.length'
  9. >
  10. <div
  11. class='user_threads__thread'
  12. v-for='(thread, index) in threads'
  13. :class='{"user_threads__thread--last": index === threads.length-1}'
  14. @click='goToThread(thread)'
  15. >
  16. <div class='user_threads__thread_bar'>
  17. <div class='user_threads__category'>{{thread.Category.name}}</div>
  18. <div class='user_threads__date'>{{thread.createdAt | formatDate('date')}}</div>
  19. </div>
  20. <div class='user_threads__name'>{{thread.name}}</div>
  21. </div>
  22. </scroll-load>
  23. <template v-else>This user hasn't started any threads yet</template>
  24. </div>
  25. </template>
  26. <script>
  27. import ScrollLoad from '../ScrollLoad'
  28. import ThreadPost from '../ThreadPost'
  29. import AjaxErrorHandler from '../../assets/js/errorHandler'
  30. export default {
  31. name: 'userThreads',
  32. props: ['username'],
  33. components: {
  34. ThreadPost,
  35. ScrollLoad
  36. },
  37. data () {
  38. return {
  39. threads: [],
  40. loadingThreads: false,
  41. nextURL: ''
  42. }
  43. },
  44. methods: {
  45. loadNewThreads () {
  46. if(this.nextURL === null) return
  47. this.loadingThreads = true
  48. this.axios
  49. .get(this.nextURL)
  50. .then(res => {
  51. this.loadingThreads = false
  52. this.threads.push(...res.data.Threads)
  53. this.nextURL = res.data.meta.nextURL
  54. })
  55. .catch((e) => {
  56. this.loadingThreads = false
  57. AjaxErrorHandler(this.$store)(e)
  58. })
  59. },
  60. goToThread (thread) {
  61. this.$router.push('/thread/' + thread.slug + '/' + thread.id)
  62. }
  63. },
  64. created () {
  65. this.axios
  66. .get(`/api/v1/user/${this.$route.params.username}?threads=true`)
  67. .then(res => {
  68. this.threads = res.data.Threads
  69. this.nextURL = res.data.meta.nextURL
  70. })
  71. .catch(AjaxErrorHandler(this.$store))
  72. }
  73. }
  74. </script>
  75. <style lang='scss' scoped>
  76. @import '../../assets/scss/variables.scss';
  77. .user_threads {
  78. @at-root #{&}__title {
  79. font-size: 1.5rem;
  80. margin-bottom: 1rem;
  81. }
  82. @at-root #{&}__thread {
  83. border-top: thin solid $color__gray--primary;
  84. padding: 0.75rem;
  85. cursor: pointer;
  86. background-color: #fff;
  87. transition: all 0.2s;
  88. &:hover {
  89. background-color: $color__lightgray--primary;
  90. }
  91. @at-root #{&}--last {
  92. border-bottom: thin solid $color__gray--primary;
  93. }
  94. }
  95. @at-root #{&}__thread_bar {
  96. display: flex;
  97. margin-bottom: 0.25rem;
  98. }
  99. @at-root #{&}__date {
  100. margin-left: 0.5rem;
  101. color: $color__gray--darkest;
  102. }
  103. @at-root #{&}__name {
  104. font-size: 1.25rem;
  105. }
  106. }
  107. </style>