ActivityItem.vue 6.0 KB

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