News.vue 3.4 KB

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