News.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class='app'>
  3. <main-header></main-header>
  4. <div class='container'>
  5. <div class='card is-fullwidth' v-for='item in news'>
  6. <header class='card-header'>
  7. <p class='card-header-title'>
  8. {{ item.title }} - {{ formatDate(item.createdAt) }}
  9. </p>
  10. </header>
  11. <div class='card-content'>
  12. <div class='content'>
  13. <p>{{ item.description }}</p>
  14. </div>
  15. <div class='sect' v-show='item.features.length > 0'>
  16. <div class='sect-head-features'>The features are so great</div>
  17. <ul class='sect-body'>
  18. <li v-for='li in item.features'>{{ li }}</li>
  19. </ul>
  20. </div>
  21. <div class='sect' v-show='item.improvements.length > 0'>
  22. <div class='sect-head-improvements'>Improvements</div>
  23. <ul class='sect-body'>
  24. <li v-for='li in item.improvements'>{{ li }}</li>
  25. </ul>
  26. </div>
  27. <div class='sect' v-show='item.bugs.length > 0'>
  28. <div class='sect-head-bugs'>Bugs Smashed</div>
  29. <ul class='sect-body'>
  30. <li v-for='li in item.bugs'>{{ li }}</li>
  31. </ul>
  32. </div>
  33. <div class='sect' v-show='item.upcoming.length > 0'>
  34. <div class='sect-head-upcoming'>Coming Soon to a Musare near you</div>
  35. <ul class='sect-body'>
  36. <li v-for='li in item.upcoming'>{{ li }}</li>
  37. </ul>
  38. </div>
  39. </div>
  40. </div>
  41. <h3 v-if="noFound" class="center">No news items were found.</h3>
  42. </div>
  43. <main-footer></main-footer>
  44. </div>
  45. </template>
  46. <script>
  47. import MainHeader from '../MainHeader.vue';
  48. import MainFooter from '../MainFooter.vue';
  49. import io from '../../io';
  50. export default {
  51. components: { MainHeader, MainFooter },
  52. methods: {
  53. formatDate: unix => {
  54. return moment(unix).format('DD-MM-YYYY');
  55. }
  56. },
  57. data() {
  58. return {
  59. news: [],
  60. noFound: false
  61. }
  62. },
  63. ready: function () {
  64. let _this = this;
  65. io.getSocket((socket) => {
  66. _this.socket = socket;
  67. _this.socket.emit('news.index', res => {
  68. _this.news = res.data;
  69. if (_this.news.length === 0) _this.noFound = true;
  70. });
  71. _this.socket.on('event:admin.news.created', news => {
  72. _this.news.unshift(news);
  73. _this.noFound = false;
  74. });
  75. _this.socket.on('event:admin.news.updated', news => {
  76. for (let n = 0; n < _this.news.length; n++) {
  77. if (_this.news[n]._id === news._id) {
  78. _this.news.$set(n, news);
  79. }
  80. }
  81. });
  82. _this.socket.on('event:admin.news.removed', news => {
  83. _this.news = _this.news.filter(item => item._id !== news._id);
  84. if (_this.news.length === 0) _this.noFound = true;
  85. });
  86. });
  87. }
  88. }
  89. </script>
  90. <style lang='scss' scoped>
  91. .card { margin-top: 50px; }
  92. .sect {
  93. div[class^='sect-head'], div[class*=' sect-head']{
  94. padding: 12px;
  95. text-transform: uppercase;
  96. font-weight: bold;
  97. color: #fff;
  98. }
  99. .sect-head-features { background-color: dodgerblue; }
  100. .sect-head-improvements { background-color: seagreen; }
  101. .sect-head-bugs { background-color: brown; }
  102. .sect-head-upcoming { background-color: mediumpurple; }
  103. .sect-body {
  104. padding: 15px 25px;
  105. li { list-style-type: disc; }
  106. }
  107. }
  108. </style>