WhatIsNew.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div v-if="news !== null">
  3. <modal title="News">
  4. <div slot="body">
  5. <div
  6. class="section news-item"
  7. v-html="marked(news.markdown)"
  8. ></div>
  9. </div>
  10. <div slot="footer">
  11. <span v-if="news.createdBy">
  12. By
  13. <user-id-to-username
  14. :user-id="news.createdBy"
  15. :alt="news.createdBy"
  16. :link="true"
  17. />
  18. @
  19. </span>
  20. {{ formatDate(news.createdAt) }}
  21. </div>
  22. </modal>
  23. </div>
  24. </template>
  25. <script>
  26. import { format } from "date-fns";
  27. import marked from "marked";
  28. import { mapGetters, mapActions } from "vuex";
  29. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  30. import Modal from "../Modal.vue";
  31. export default {
  32. components: { Modal, UserIdToUsername },
  33. data() {
  34. return {
  35. isModalActive: false,
  36. news: null
  37. };
  38. },
  39. computed: {
  40. ...mapGetters({
  41. socket: "websockets/getSocket"
  42. })
  43. },
  44. mounted() {
  45. marked.use({
  46. renderer: {
  47. table(header, body) {
  48. return `<table class="table is-striped">
  49. <thead>${header}</thead>
  50. <tbody>${body}</tbody>
  51. </table>`;
  52. }
  53. }
  54. });
  55. this.socket.dispatch("news.newest", res => {
  56. if (res.status !== "success") return;
  57. const { news } = res.data;
  58. this.news = news;
  59. if (this.news && localStorage.getItem("firstVisited")) {
  60. if (localStorage.getItem("whatIsNew")) {
  61. if (
  62. parseInt(localStorage.getItem("whatIsNew")) <
  63. news.createdAt
  64. ) {
  65. this.openModal("whatIsNew");
  66. localStorage.setItem("whatIsNew", news.createdAt);
  67. }
  68. } else {
  69. if (
  70. parseInt(localStorage.getItem("firstVisited")) <
  71. news.createdAt
  72. )
  73. this.openModal("whatIsNew");
  74. localStorage.setItem("whatIsNew", news.createdAt);
  75. }
  76. } else if (!localStorage.getItem("firstVisited"))
  77. localStorage.setItem("firstVisited", Date.now());
  78. });
  79. },
  80. methods: {
  81. marked,
  82. formatDate: unix => {
  83. return format(unix, "HH:ii:ss dd-MM-yyyy");
  84. },
  85. ...mapActions("modalVisibility", ["openModal"])
  86. }
  87. };
  88. </script>
  89. <style lang="scss" scoped>
  90. .night-mode {
  91. .modal-card,
  92. .modal-card-head,
  93. .modal-card-body {
  94. background-color: var(--dark-grey-3);
  95. }
  96. strong,
  97. p {
  98. color: var(--light-grey-2);
  99. }
  100. }
  101. .modal-card-head {
  102. border-bottom: none;
  103. background-color: ghostwhite;
  104. padding: 15px;
  105. }
  106. .modal-card-title {
  107. font-size: 14px;
  108. }
  109. .news-item {
  110. box-shadow: unset !important;
  111. }
  112. .delete {
  113. background: transparent;
  114. &:hover {
  115. background: transparent;
  116. }
  117. &:before,
  118. &:after {
  119. background-color: var(--light-grey-3);
  120. }
  121. }
  122. .sect {
  123. div[class^="sect-head"],
  124. div[class*=" sect-head"] {
  125. padding: 12px;
  126. text-transform: uppercase;
  127. font-weight: bold;
  128. color: var(--white);
  129. }
  130. .sect-head-features {
  131. background-color: dodgerblue;
  132. }
  133. .sect-head-improvements {
  134. background-color: seagreen;
  135. }
  136. .sect-head-bugs {
  137. background-color: brown;
  138. }
  139. .sect-head-upcoming {
  140. background-color: mediumpurple;
  141. }
  142. .sect-body {
  143. padding: 15px 25px;
  144. li {
  145. list-style-type: disc;
  146. }
  147. }
  148. }
  149. </style>