ActivityItem.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="item activity-item universal-item">
  3. <div :class="[theme, 'thumbnail']">
  4. <img
  5. v-if="activity.payload.thumbnail"
  6. :src="activity.payload.thumbnail"
  7. :alt="textOnlyMessage"
  8. />
  9. <i class="material-icons activity-type-icon">{{ getIcon() }}</i>
  10. </div>
  11. <div class="left-part">
  12. <component
  13. class="item-title"
  14. :title="textOnlyMessage"
  15. :is="formattedMessage"
  16. />
  17. <p class="item-description">
  18. {{
  19. formatDistance(parseISO(activity.createdAt), new Date(), {
  20. addSuffix: true
  21. })
  22. }}
  23. </p>
  24. </div>
  25. <div class="universal-item-actions">
  26. <slot name="actions" />
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { mapActions } from "vuex";
  32. import { formatDistance, parseISO } from "date-fns";
  33. export default {
  34. props: {
  35. activity: {
  36. type: Object,
  37. default: () => {}
  38. }
  39. },
  40. data() {
  41. return {
  42. theme: "blue"
  43. };
  44. },
  45. computed: {
  46. formattedMessage() {
  47. const { songId, playlistId, stationId } = this.activity.payload;
  48. let { message } = this.activity.payload;
  49. if (songId) {
  50. message = message.replace(/<songId>(.*)<\/songId>/g, "$1");
  51. }
  52. if (playlistId) {
  53. message = message.replace(
  54. /<playlistId>(.*)<\/playlistId>/g,
  55. `<a href='#' class='activity-item-link' @click='showPlaylist("${playlistId}")'>$1</a>`
  56. );
  57. }
  58. if (stationId) {
  59. message = message.replace(
  60. /<stationId>(.*)<\/stationId>/g,
  61. `<router-link class='activity-item-link' :to="{ name: 'station', params: { id: '${stationId}' } }">$1</router-link>`
  62. );
  63. }
  64. return {
  65. template: `<p>${message}</p>`,
  66. methods: { showPlaylist: this.showPlaylist }
  67. };
  68. },
  69. textOnlyMessage() {
  70. const { songId, playlistId, stationId } = this.activity.payload;
  71. let { message } = this.activity.payload;
  72. if (songId) {
  73. message = message.replace(/<songId>(.*)<\/songId>/g, "$1");
  74. }
  75. if (playlistId) {
  76. message = message.replace(
  77. /<playlistId>(.*)<\/playlistId>/g,
  78. `$1`
  79. );
  80. }
  81. if (stationId) {
  82. message = message.replace(
  83. /<stationId>(.*)<\/stationId>/g,
  84. `$1`
  85. );
  86. }
  87. return message;
  88. }
  89. },
  90. mounted() {
  91. if (this.activity.type === "station__edit_theme")
  92. this.theme = this.activity.payload.message.replace(
  93. /to\s(\w+)/g,
  94. "$1"
  95. );
  96. },
  97. methods: {
  98. getIcon() {
  99. const icons = {
  100. /** User */
  101. user__joined: "account_circle",
  102. user__edit_bio: "create",
  103. user__edit_avatar: "insert_photo",
  104. user__edit_name: "create",
  105. user__edit_location: "place",
  106. user__toggle_nightmode: "nightlight_round",
  107. user__toggle_autoskip_disliked_songs: "thumb_down_alt",
  108. /** Songs */
  109. song__report: "flag",
  110. song__like: "thumb_up_alt",
  111. song__dislike: "thumb_down_alt",
  112. song__unlike: "not_interested",
  113. song__undislike: "not_interested",
  114. /** Stations */
  115. station__favorite: "star",
  116. station__unfavorite: "star_border",
  117. station__create: "create",
  118. station__remove: "delete",
  119. station__edit_theme: "color_lens",
  120. station__edit_name: "create",
  121. station__edit_display_name: "create",
  122. station__edit_description: "create",
  123. station__edit_privacy: "security",
  124. station__edit_genres: "create",
  125. station__edit_blacklisted_genres: "create",
  126. /** Playlists */
  127. playlist__create: "create",
  128. playlist__remove: "delete",
  129. playlist__remove_song: "not_interested",
  130. playlist__remove_songs: "not_interested",
  131. playlist__add_song: "library_add",
  132. playlist__add_songs: "library_add",
  133. playlist__edit_privacy: "security",
  134. playlist__edit_display_name: "create",
  135. playlist__import_playlist: "publish"
  136. };
  137. return icons[this.activity.type];
  138. },
  139. showPlaylist(playlistId) {
  140. this.editPlaylist(playlistId);
  141. this.openModal({ sector: "station", modal: "editPlaylist" });
  142. },
  143. ...mapActions("user/playlists", ["editPlaylist"]),
  144. formatDistance,
  145. parseISO,
  146. ...mapActions("modalVisibility", ["openModal"])
  147. }
  148. };
  149. </script>
  150. <style lang="scss">
  151. .activity-item-link {
  152. color: var(--primary-color) !important;
  153. &:hover {
  154. border-color: #dbdbdb !important;
  155. }
  156. }
  157. </style>
  158. <style lang="scss" scoped>
  159. .activity-item {
  160. height: 72px;
  161. border: 0.5px var(--light-grey-3) solid;
  162. border-radius: 3px;
  163. padding: 0;
  164. .thumbnail {
  165. position: relative;
  166. display: flex;
  167. align-items: center;
  168. justify-content: center;
  169. min-width: 70.5px;
  170. max-width: 70.5px;
  171. height: 70.5px;
  172. &.red {
  173. background-color: var(--red);
  174. }
  175. &.green {
  176. background-color: var(--green);
  177. }
  178. &.blue {
  179. background-color: var(--primary-color);
  180. }
  181. &.orange {
  182. background-color: var(--orange);
  183. }
  184. &.yellow {
  185. background-color: var(--yellow);
  186. }
  187. &.purple {
  188. background-color: var(--purple);
  189. }
  190. &.teal {
  191. background-color: var(--teal);
  192. }
  193. .activity-type-icon {
  194. position: absolute;
  195. color: var(--light-grey);
  196. font-size: 25px;
  197. background-color: rgba(0, 0, 0, 0.8);
  198. padding: 5px;
  199. border-radius: 100%;
  200. }
  201. }
  202. .left-part {
  203. flex: 1;
  204. padding: 12px;
  205. width: calc(100% - 150px);
  206. .item-title {
  207. margin: 0;
  208. font-size: 16px;
  209. }
  210. }
  211. .universal-item-actions {
  212. right: 10px;
  213. position: sticky;
  214. a {
  215. border-bottom: 0;
  216. }
  217. }
  218. }
  219. </style>