SongItem.vue 7.6 KB

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