ActivityItem.vue 5.2 KB

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