News.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class="app">
  3. <metadata title="News" />
  4. <main-header />
  5. <div class="container">
  6. <div class="content-wrapper">
  7. <div
  8. v-for="(item, index) in news"
  9. :key="index"
  10. class="card is-fullwidth"
  11. >
  12. <header class="card-header">
  13. <p class="card-header-title">
  14. {{ item.title }} - {{ formatDate(item.createdAt) }}
  15. </p>
  16. </header>
  17. <div class="card-content">
  18. <div class="content">
  19. <p>{{ item.description }}</p>
  20. </div>
  21. <div v-show="item.features.length > 0" class="sect">
  22. <div class="sect-head-features">
  23. The features are so great
  24. </div>
  25. <ul class="sect-body">
  26. <li
  27. v-for="(feature,
  28. itemIndex) in item.features"
  29. :key="itemIndex"
  30. >
  31. {{ feature }}
  32. </li>
  33. </ul>
  34. </div>
  35. <div v-show="item.improvements.length > 0" class="sect">
  36. <div class="sect-head-improvements">
  37. Improvements
  38. </div>
  39. <ul class="sect-body">
  40. <li
  41. v-for="(improvement,
  42. itemIndex) in item.improvements"
  43. :key="itemIndex"
  44. >
  45. {{ improvement }}
  46. </li>
  47. </ul>
  48. </div>
  49. <div v-show="item.bugs.length > 0" class="sect">
  50. <div class="sect-head-bugs">Bugs Smashed</div>
  51. <ul class="sect-body">
  52. <li
  53. v-for="(bug, itemIndex) in item.bugs"
  54. :key="itemIndex"
  55. >
  56. {{ bug }}
  57. </li>
  58. </ul>
  59. </div>
  60. <div v-show="item.upcoming.length > 0" class="sect">
  61. <div class="sect-head-upcoming">
  62. Coming Soon to a Musare near you
  63. </div>
  64. <ul class="sect-body">
  65. <li
  66. v-for="(upcoming,
  67. itemIndex) in item.upcoming"
  68. :key="itemIndex"
  69. >
  70. {{ upcoming }}
  71. </li>
  72. </ul>
  73. </div>
  74. </div>
  75. </div>
  76. <h3 v-if="noFound" class="has-text-centered page-title">
  77. No news items were found.
  78. </h3>
  79. </div>
  80. </div>
  81. <main-footer />
  82. </div>
  83. </template>
  84. <script>
  85. import { format } from "date-fns";
  86. import { mapGetters } from "vuex";
  87. import MainHeader from "@/components/layout/MainHeader.vue";
  88. import MainFooter from "@/components/layout/MainFooter.vue";
  89. export default {
  90. components: { MainHeader, MainFooter },
  91. data() {
  92. return {
  93. news: [],
  94. noFound: false
  95. };
  96. },
  97. computed: mapGetters({
  98. socket: "websockets/getSocket"
  99. }),
  100. mounted() {
  101. this.socket.dispatch("news.index", res => {
  102. this.news = res.data;
  103. if (this.news.length === 0) this.noFound = true;
  104. });
  105. this.socket.on("event:admin.news.created", news => {
  106. this.news.unshift(news);
  107. this.noFound = false;
  108. });
  109. this.socket.on("event:admin.news.updated", news => {
  110. for (let n = 0; n < this.news.length; n += 1) {
  111. if (this.news[n]._id === news._id) {
  112. this.$set(this.news, n, news);
  113. }
  114. }
  115. });
  116. this.socket.on("event:admin.news.removed", news => {
  117. this.news = this.news.filter(item => item._id !== news._id);
  118. if (this.news.length === 0) this.noFound = true;
  119. });
  120. },
  121. methods: {
  122. formatDate: unix => {
  123. return format(unix, "dd-MM-yyyy");
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. .night-mode {
  130. p {
  131. color: var(--light-grey-2);
  132. }
  133. }
  134. .card {
  135. margin-top: 50px;
  136. }
  137. .sect {
  138. div[class^="sect-head"],
  139. div[class*=" sect-head"] {
  140. padding: 12px;
  141. text-transform: uppercase;
  142. font-weight: bold;
  143. color: var(--white);
  144. }
  145. .sect-head-features {
  146. background-color: dodgerblue;
  147. }
  148. .sect-head-improvements {
  149. background-color: seagreen;
  150. }
  151. .sect-head-bugs {
  152. background-color: brown;
  153. }
  154. .sect-head-upcoming {
  155. background-color: mediumpurple;
  156. }
  157. .sect-body {
  158. padding: 15px 25px;
  159. li {
  160. list-style-type: disc;
  161. }
  162. }
  163. }
  164. </style>