Thread.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div class='route_container'>
  3. <header class='thread_header'>
  4. <div
  5. class='thread_header__thread_title thread_header__thread_title--app_header'
  6. :class='{
  7. "thread_header__thread_title--app_header-show": headerTitle
  8. }'
  9. >
  10. {{thread}}
  11. </div>
  12. <div class='thread_header__thread_title' ref='title'>
  13. {{thread}}
  14. </div>
  15. <button class='button thread_header__reply_button' @click='showEditor(true)'>Reply to thread</button>
  16. </header>
  17. <input-editor name='thread' float='true' :replying='replyingUsername' v-on:submit='addPost'></input-editor>
  18. <div class='posts'>
  19. <div class='post' v-for='post in posts'>
  20. <div class='post__meta_data'>
  21. <div class='post__avatar'>{{post.username[0]}}</div>
  22. <div class='post__user'>{{post.username}}</div>
  23. <span class='fa fa-long-arrow-right fa-fw' v-if='post.replyingUsername'></span>
  24. <div class='post__reply' v-if='post.replyingUsername'>{{post.replyingUsername}}</div>
  25. <div class='post__date'>{{post.date | formatDate('time|date', ', ')}}</div>
  26. </div>
  27. <div class='post__content' v-html='post.content'></div>
  28. <div class='post__actions'>
  29. <div class='post__action post__share'>Share</div>
  30. <div class='post__action post__reply' @click='reply("id", post.username)'>Reply</div>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import InputEditor from '../InputEditor'
  38. import throttle from 'lodash.throttle'
  39. export default {
  40. name: 'Thread',
  41. components: {
  42. InputEditor
  43. },
  44. data () {
  45. return { headerTitle: false }
  46. },
  47. computed: {
  48. thread () {
  49. return this.$store.state.thread.thread;
  50. },
  51. posts () {
  52. return this.$store.state.thread.posts;
  53. },
  54. replyingUsername () {
  55. return this.$store.state.thread.replying.username
  56. }
  57. },
  58. methods: {
  59. showEditor (clearReply) {
  60. this.$store.commit({
  61. type: 'showEditor',
  62. name: 'thread',
  63. value: true
  64. });
  65. if(clearReply) {
  66. this.$store.commit({
  67. type: 'setReply',
  68. username: '',
  69. id: ''
  70. });
  71. }
  72. },
  73. reply (id, username) {
  74. this.$store.commit({
  75. type: 'setReply',
  76. username,
  77. id
  78. });
  79. this.showEditor();
  80. },
  81. addPost () {
  82. this.$store.dispatch('addPostAsync');
  83. }
  84. },
  85. mounted () {
  86. var self = this;
  87. var setHeader = function() {
  88. if(!self.$refs.title) return;
  89. if(self.$refs.title.getBoundingClientRect().top <= 32) {
  90. self.headerTitle = true;
  91. } else {
  92. self.headerTitle = false;
  93. }
  94. };
  95. setHeader();
  96. document.addEventListener('scroll', throttle(setHeader, 200));
  97. }
  98. }
  99. </script>
  100. <style lang='scss' scoped>
  101. @import '../../assets/scss/variables.scss';
  102. .thread_header {
  103. display: flex;
  104. justify-content: space-between;
  105. @at-root #{&}__thread_title {
  106. @include text($font--role-default, 3rem, 400);
  107. margin-bottom: 1rem;
  108. @at-root #{&}--app_header {
  109. position: fixed;
  110. width: 80%;
  111. z-index: 2;
  112. text-align: center;
  113. left: 0;
  114. font-size: 2rem;
  115. top: 1rem;
  116. opacity: 0;
  117. pointer-events: none;
  118. transition: opacity 0.2s;
  119. @at-root #{&}-show {
  120. opacity: 1;
  121. transition: opacity 0.2s;
  122. }
  123. }
  124. }
  125. @at-root #{&}__reply_button {
  126. height: 3rem;
  127. position: fixed;
  128. right: 10%;
  129. margin-top: 0.75rem;
  130. }
  131. }
  132. .posts {
  133. width: 80%;
  134. &:last-child {
  135. border-bottom: thin solid $color__gray--primary;
  136. }
  137. }
  138. .post {
  139. border-top: thin solid $color__gray--primary;
  140. margin: 0.5rem 0;
  141. @at-root #{&}__meta_data {
  142. display: flex;
  143. padding-top: 0.75rem;
  144. position: relative;
  145. margin-left: 4rem;
  146. }
  147. @at-root #{&}__avatar {
  148. position: absolute;
  149. height: 3rem;
  150. width: 3rem;
  151. line-height: 3rem;
  152. @include text($font--role-emphasis, 2rem)
  153. text-align: center;
  154. border-radius: 100%;
  155. background-color: $color__gray--darkest;
  156. color: #fff;
  157. left: -4rem;
  158. }
  159. @at-root #{&}__user {
  160. @include text($font--role-default, 1rem, 600);
  161. margin-right: 0.5rem;
  162. }
  163. @at-root #{&}__reply {
  164. margin: 0 0.5rem;
  165. }
  166. @at-root #{&}__date {
  167. color: $color__gray--darkest;
  168. margin-right: 0.5rem;
  169. }
  170. @at-root #{&}__content {
  171. padding: 0.5rem 0 0.5rem 4rem;
  172. }
  173. @at-root #{&}__actions {
  174. padding: 0.5rem 0 0.75rem 4rem;
  175. display: flex;
  176. justify-content: flex-end;
  177. }
  178. @at-root #{&}__action {
  179. color: $color__gray--darkest;
  180. cursor: pointer;
  181. margin-right: 0.75rem;
  182. transition: all 0.2s;
  183. &:hover {
  184. color: $color__darkgray--primary;
  185. }
  186. &:active {
  187. color: $color__darkgray--darkest;
  188. }
  189. }
  190. }
  191. </style>