News.vue 3.4 KB

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