ActivityItem.vue 5.5 KB

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