WhatIsNew.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div v-if="news !== null">
  3. <modal :title="`News posted ${timeCreated}`">
  4. <div slot="body">
  5. <div
  6. class="section news-item"
  7. v-html="marked(news.markdown)"
  8. ></div>
  9. </div>
  10. </modal>
  11. </div>
  12. </template>
  13. <script>
  14. import { formatDistance } from "date-fns";
  15. import marked from "marked";
  16. import { mapGetters, mapActions } from "vuex";
  17. import Modal from "../Modal.vue";
  18. export default {
  19. components: { Modal },
  20. data() {
  21. return {
  22. isModalActive: false,
  23. news: null
  24. };
  25. },
  26. computed: {
  27. ...mapGetters({
  28. socket: "websockets/getSocket"
  29. }),
  30. timeCreated() {
  31. return formatDistance(this.news.createdAt, new Date(), {
  32. addSuffix: true
  33. });
  34. }
  35. },
  36. mounted() {
  37. this.socket.dispatch("news.newest", res => {
  38. if (res.status !== "success") return;
  39. const { news } = res.data;
  40. this.news = news;
  41. if (this.news && localStorage.getItem("firstVisited")) {
  42. if (localStorage.getItem("whatIsNew")) {
  43. if (
  44. parseInt(localStorage.getItem("whatIsNew")) <
  45. news.createdAt
  46. ) {
  47. this.openModal("whatIsNew");
  48. localStorage.setItem("whatIsNew", news.createdAt);
  49. }
  50. } else {
  51. if (
  52. parseInt(localStorage.getItem("firstVisited")) <
  53. news.createdAt
  54. )
  55. this.openModal("whatIsNew");
  56. localStorage.setItem("whatIsNew", news.createdAt);
  57. }
  58. } else if (!localStorage.getItem("firstVisited"))
  59. localStorage.setItem("firstVisited", Date.now());
  60. });
  61. },
  62. methods: {
  63. marked,
  64. ...mapActions("modalVisibility", ["openModal"])
  65. }
  66. };
  67. </script>
  68. <style lang="scss" scoped>
  69. .night-mode {
  70. .modal-card,
  71. .modal-card-head,
  72. .modal-card-body {
  73. background-color: var(--dark-grey-3);
  74. }
  75. strong,
  76. p {
  77. color: var(--light-grey-2);
  78. }
  79. }
  80. .modal-card-head {
  81. border-bottom: none;
  82. background-color: ghostwhite;
  83. padding: 15px;
  84. }
  85. .modal-card-title {
  86. font-size: 14px;
  87. }
  88. .delete {
  89. background: transparent;
  90. &:hover {
  91. background: transparent;
  92. }
  93. &:before,
  94. &:after {
  95. background-color: var(--light-grey-3);
  96. }
  97. }
  98. .sect {
  99. div[class^="sect-head"],
  100. div[class*=" sect-head"] {
  101. padding: 12px;
  102. text-transform: uppercase;
  103. font-weight: bold;
  104. color: var(--white);
  105. }
  106. .sect-head-features {
  107. background-color: dodgerblue;
  108. }
  109. .sect-head-improvements {
  110. background-color: seagreen;
  111. }
  112. .sect-head-bugs {
  113. background-color: brown;
  114. }
  115. .sect-head-upcoming {
  116. background-color: mediumpurple;
  117. }
  118. .sect-body {
  119. padding: 15px 25px;
  120. li {
  121. list-style-type: disc;
  122. }
  123. }
  124. }
  125. </style>