SongItem.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div
  3. class="universal-item song-item"
  4. :class="{ 'with-duration': duration }"
  5. v-if="song"
  6. >
  7. <div class="thumbnail-and-info">
  8. <slot v-if="$slots.leftIcon" name="leftIcon" />
  9. <song-thumbnail :song="song" v-if="thumbnail" />
  10. <div class="song-info">
  11. <h6 v-if="header">{{ header }}</h6>
  12. <div class="song-title">
  13. <h4
  14. :class="{
  15. 'item-title': true,
  16. 'no-artists':
  17. !song.artists ||
  18. (song.artists && song.artists.length < 1)
  19. }"
  20. :title="song.title"
  21. >
  22. {{ song.title }}
  23. </h4>
  24. <i
  25. v-if="song.verified"
  26. class="material-icons verified-song"
  27. content="Verified Song"
  28. v-tippy="{ theme: 'info' }"
  29. >
  30. check_circle
  31. </i>
  32. </div>
  33. <h5
  34. class="item-description"
  35. v-if="formatArtists()"
  36. :title="formatArtists()"
  37. >
  38. {{ formatArtists() }}
  39. </h5>
  40. <p class="song-request-time" v-if="requestedBy">
  41. Requested by
  42. <strong>
  43. <user-id-to-username
  44. v-if="song.requestedBy"
  45. :key="song._id"
  46. :user-id="song.requestedBy"
  47. :link="true"
  48. />
  49. <span v-else>station</span>
  50. {{ formatedRequestedAt }}
  51. ago
  52. </strong>
  53. </p>
  54. </div>
  55. </div>
  56. <div class="duration-and-actions">
  57. <p v-if="duration" class="song-duration">
  58. {{ utils.formatTime(song.duration) }}
  59. </p>
  60. <div
  61. class="universal-item-actions"
  62. v-if="disabledActions.indexOf('all') === -1"
  63. >
  64. <tippy
  65. v-if="loggedIn && hoveredTippy"
  66. :touch="true"
  67. :interactive="true"
  68. placement="left"
  69. theme="songActions"
  70. ref="songActions"
  71. trigger="click"
  72. >
  73. <i
  74. class="material-icons action-dropdown-icon"
  75. content="Song Options"
  76. v-tippy
  77. >more_horiz</i
  78. >
  79. <template #content>
  80. <div class="icons-group">
  81. <a
  82. v-if="disabledActions.indexOf('youtube') === -1"
  83. target="_blank"
  84. :href="`https://www.youtube.com/watch?v=${song.youtubeId}`"
  85. content="View on Youtube"
  86. v-tippy
  87. >
  88. <div class="youtube-icon"></div>
  89. </a>
  90. <i
  91. v-if="disabledActions.indexOf('report') === -1"
  92. class="material-icons report-icon"
  93. @click="report(song)"
  94. content="Report Song"
  95. v-tippy
  96. >
  97. flag
  98. </i>
  99. <add-to-playlist-dropdown
  100. v-if="
  101. disabledActions.indexOf('addToPlaylist') ===
  102. -1
  103. "
  104. :song="song"
  105. placement="top-end"
  106. >
  107. <template #button>
  108. <i
  109. class="material-icons add-to-playlist-icon"
  110. content="Add Song to Playlist"
  111. v-tippy
  112. >playlist_add</i
  113. >
  114. </template>
  115. </add-to-playlist-dropdown>
  116. <i
  117. v-if="
  118. loggedIn &&
  119. userRole === 'admin' &&
  120. disabledActions.indexOf('edit') === -1
  121. "
  122. class="material-icons edit-icon"
  123. @click="edit(song)"
  124. content="Edit Song"
  125. v-tippy
  126. >
  127. edit
  128. </i>
  129. <slot name="tippyActions" />
  130. </div>
  131. </template>
  132. </tippy>
  133. <i
  134. class="material-icons action-dropdown-icon"
  135. v-else-if="loggedIn && !hoveredTippy"
  136. @mouseenter="hoverTippy()"
  137. >more_horiz</i
  138. >
  139. <a
  140. v-else-if="
  141. !loggedIn && disabledActions.indexOf('youtube') === -1
  142. "
  143. target="_blank"
  144. :href="`https://www.youtube.com/watch?v=${song.youtubeId}`"
  145. content="View on Youtube"
  146. v-tippy
  147. >
  148. <div class="youtube-icon"></div>
  149. </a>
  150. </div>
  151. <div class="universal-item-actions" v-if="$slots.actions">
  152. <slot name="actions" />
  153. </div>
  154. </div>
  155. </div>
  156. </template>
  157. <script>
  158. import { mapActions, mapState } from "vuex";
  159. import { formatDistance, parseISO } from "date-fns";
  160. import AddToPlaylistDropdown from "./AddToPlaylistDropdown.vue";
  161. import SongThumbnail from "./SongThumbnail.vue";
  162. import utils from "../../js/utils";
  163. export default {
  164. components: { AddToPlaylistDropdown, SongThumbnail },
  165. props: {
  166. song: {
  167. type: Object,
  168. default: () => {}
  169. },
  170. requestedBy: {
  171. type: Boolean,
  172. default: false
  173. },
  174. duration: {
  175. type: Boolean,
  176. default: true
  177. },
  178. thumbnail: {
  179. type: Boolean,
  180. default: true
  181. },
  182. disabledActions: {
  183. type: Array,
  184. default: () => []
  185. },
  186. header: {
  187. type: String,
  188. default: null
  189. }
  190. },
  191. data() {
  192. return {
  193. utils,
  194. formatedRequestedAt: null,
  195. formatRequestedAtInterval: null,
  196. hoveredTippy: false
  197. };
  198. },
  199. computed: {
  200. ...mapState({
  201. loggedIn: state => state.user.auth.loggedIn,
  202. userRole: state => state.user.auth.role
  203. })
  204. },
  205. mounted() {
  206. if (this.requestedBy) {
  207. this.formatRequestedAt();
  208. this.formatRequestedAtInterval = setInterval(() => {
  209. this.formatRequestedAt();
  210. }, 30000);
  211. }
  212. },
  213. unmounted() {
  214. clearInterval(this.formatRequestedAtInterval);
  215. },
  216. methods: {
  217. formatRequestedAt() {
  218. if (this.requestedBy && this.song.requestedAt)
  219. this.formatedRequestedAt = this.formatDistance(
  220. parseISO(this.song.requestedAt),
  221. new Date()
  222. );
  223. },
  224. formatArtists() {
  225. if (this.song.artists.length === 1) {
  226. return this.song.artists[0];
  227. }
  228. if (this.song.artists.length === 2) {
  229. return this.song.artists.join(" & ");
  230. }
  231. if (this.song.artists.length > 2) {
  232. return `${this.song.artists
  233. .slice(0, -1)
  234. .join(", ")} & ${this.song.artists.slice(-1)}`;
  235. }
  236. return null;
  237. },
  238. hideTippyElements() {
  239. this.$refs.songActions.tippy.hide();
  240. setTimeout(
  241. () =>
  242. Array.from(
  243. document.querySelectorAll(".tippy-popper")
  244. ).forEach(popper => popper._tippy.hide()),
  245. 500
  246. );
  247. },
  248. hoverTippy() {
  249. this.hoveredTippy = true;
  250. },
  251. report(song) {
  252. this.hideTippyElements();
  253. this.openModal({ modal: "report", data: { song } });
  254. },
  255. edit(song) {
  256. this.hideTippyElements();
  257. this.editSong({ songId: song._id });
  258. this.openModal("editSong");
  259. },
  260. ...mapActions("modals/editSong", ["editSong"]),
  261. ...mapActions("modalVisibility", ["openModal"]),
  262. formatDistance,
  263. parseISO
  264. }
  265. };
  266. </script>
  267. <style lang="less" scoped>
  268. .night-mode {
  269. .song-item {
  270. background-color: var(--dark-grey-2) !important;
  271. border: 0 !important;
  272. }
  273. }
  274. :deep(#nav-dropdown) {
  275. margin-top: 36px;
  276. width: 0;
  277. height: 0;
  278. .nav-dropdown-items {
  279. width: 250px;
  280. max-width: 100vw;
  281. position: relative;
  282. right: 175px;
  283. }
  284. }
  285. .song-item {
  286. min-height: 70px;
  287. &:not(:last-of-type) {
  288. margin-bottom: 10px;
  289. }
  290. .thumbnail-and-info,
  291. .duration-and-actions {
  292. display: flex;
  293. align-items: center;
  294. }
  295. .duration-and-actions {
  296. margin-left: 5px;
  297. .universal-item-actions div i {
  298. margin-left: 5px;
  299. }
  300. }
  301. .thumbnail-and-info {
  302. min-width: 0;
  303. }
  304. .thumbnail {
  305. min-width: 70px;
  306. width: 70px;
  307. height: 70px;
  308. margin: -7.5px;
  309. margin-right: calc(20px - 7.5px);
  310. }
  311. .song-info {
  312. display: flex;
  313. flex-direction: column;
  314. justify-content: center;
  315. // margin-left: 20px;
  316. min-width: 0;
  317. *:not(i) {
  318. margin: 0;
  319. font-family: Karla, Arial, sans-serif;
  320. }
  321. h6 {
  322. color: var(--primary-color) !important;
  323. font-weight: bold;
  324. font-size: 17px;
  325. margin-bottom: 5px;
  326. }
  327. .song-title {
  328. display: flex;
  329. flex-direction: row;
  330. .item-title {
  331. font-size: 18px;
  332. }
  333. .verified-song {
  334. margin-left: 5px;
  335. }
  336. .item-title.no-artists {
  337. display: -webkit-inline-box;
  338. font-size: 16px;
  339. white-space: normal;
  340. -webkit-box-orient: vertical;
  341. -webkit-line-clamp: 2;
  342. }
  343. }
  344. .item-description {
  345. line-height: 120%;
  346. }
  347. .song-request-time {
  348. font-size: 11px;
  349. overflow: hidden;
  350. text-overflow: ellipsis;
  351. white-space: nowrap;
  352. }
  353. }
  354. .song-duration {
  355. font-size: 20px;
  356. }
  357. .edit-icon {
  358. color: var(--primary-color);
  359. }
  360. }
  361. </style>