News.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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, index) in item.features"
  28. :key="index"
  29. >
  30. {{ feature }}
  31. </li>
  32. </ul>
  33. </div>
  34. <div v-show="item.improvements.length > 0" class="sect">
  35. <div class="sect-head-improvements">
  36. Improvements
  37. </div>
  38. <ul class="sect-body">
  39. <li
  40. v-for="(improvement,
  41. ind) in item.improvements"
  42. :key="ind"
  43. >
  44. {{ improvement }}
  45. </li>
  46. </ul>
  47. </div>
  48. <div v-show="item.bugs.length > 0" class="sect">
  49. <div class="sect-head-bugs">Bugs Smashed</div>
  50. <ul class="sect-body">
  51. <li
  52. v-for="(bug, index) in item.bugs"
  53. :key="index"
  54. >
  55. {{ bug }}
  56. </li>
  57. </ul>
  58. </div>
  59. <div v-show="item.upcoming.length > 0" class="sect">
  60. <div class="sect-head-upcoming">
  61. Coming Soon to a Musare near you
  62. </div>
  63. <ul class="sect-body">
  64. <li
  65. v-for="(upcoming, index) in item.upcoming"
  66. :key="index"
  67. >
  68. {{ upcoming }}
  69. </li>
  70. </ul>
  71. </div>
  72. </div>
  73. </div>
  74. <h3 v-if="noFound" class="has-text-centered page-title">
  75. No news items were found.
  76. </h3>
  77. </div>
  78. </div>
  79. <main-footer />
  80. </div>
  81. </template>
  82. <script>
  83. import { format } from "date-fns";
  84. import Vue from "vue";
  85. import MainHeader from "../components/layout/MainHeader.vue";
  86. import MainFooter from "../components/layout/MainFooter.vue";
  87. import io from "../io";
  88. export default {
  89. components: { MainHeader, MainFooter },
  90. data() {
  91. return {
  92. news: [],
  93. noFound: false
  94. };
  95. },
  96. mounted() {
  97. io.getSocket(socket => {
  98. this.socket = socket;
  99. this.socket.emit("news.index", res => {
  100. this.news = res.data;
  101. if (this.news.length === 0) this.noFound = true;
  102. });
  103. this.socket.on("event:admin.news.created", news => {
  104. this.news.unshift(news);
  105. this.noFound = false;
  106. });
  107. this.socket.on("event:admin.news.updated", news => {
  108. for (let n = 0; n < this.news.length; n += 1) {
  109. if (this.news[n]._id === news._id) {
  110. Vue.set(this.news, n, news);
  111. }
  112. }
  113. });
  114. this.socket.on("event:admin.news.removed", news => {
  115. this.news = this.news.filter(item => item._id !== news._id);
  116. if (this.news.length === 0) this.noFound = true;
  117. });
  118. });
  119. },
  120. methods: {
  121. formatDate: unix => {
  122. return format(unix, "dd-MM-yyyy");
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. @import "../styles/global.scss";
  129. .night-mode {
  130. p {
  131. color: #ddd;
  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: $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>