News.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 Vue from "vue";
  82. import MainHeader from "../MainHeader.vue";
  83. import MainFooter from "../MainFooter.vue";
  84. import io from "../../io";
  85. export default {
  86. components: { MainHeader, MainFooter },
  87. data() {
  88. return {
  89. news: [],
  90. noFound: false
  91. };
  92. },
  93. mounted() {
  94. io.getSocket(socket => {
  95. this.socket = socket;
  96. this.socket.emit("news.index", res => {
  97. this.news = res.data;
  98. if (this.news.length === 0) this.noFound = true;
  99. });
  100. this.socket.on("event:admin.news.created", news => {
  101. this.news.unshift(news);
  102. this.noFound = false;
  103. });
  104. this.socket.on("event:admin.news.updated", news => {
  105. for (let n = 0; n < this.news.length; n += 1) {
  106. if (this.news[n]._id === news._id) {
  107. Vue.set(this.news, n, news);
  108. }
  109. }
  110. });
  111. this.socket.on("event:admin.news.removed", news => {
  112. this.news = this.news.filter(item => item._id !== news._id);
  113. if (this.news.length === 0) this.noFound = true;
  114. });
  115. });
  116. },
  117. methods: {
  118. formatDate: unix => {
  119. return format(unix, "dd-MM-yyyy");
  120. }
  121. }
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. @import "styles/global.scss";
  126. .night-mode {
  127. p {
  128. color: #ddd;
  129. }
  130. }
  131. .card {
  132. margin-top: 50px;
  133. }
  134. .sect {
  135. div[class^="sect-head"],
  136. div[class*=" sect-head"] {
  137. padding: 12px;
  138. text-transform: uppercase;
  139. font-weight: bold;
  140. color: $white;
  141. }
  142. .sect-head-features {
  143. background-color: dodgerblue;
  144. }
  145. .sect-head-improvements {
  146. background-color: seagreen;
  147. }
  148. .sect-head-bugs {
  149. background-color: brown;
  150. }
  151. .sect-head-upcoming {
  152. background-color: mediumpurple;
  153. }
  154. .sect-body {
  155. padding: 15px 25px;
  156. li {
  157. list-style-type: disc;
  158. }
  159. }
  160. }
  161. </style>