SongItem.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 UserIdToUsername from "./UserIdToUsername.vue";
  162. import SongThumbnail from "./SongThumbnail.vue";
  163. import utils from "../../js/utils";
  164. export default {
  165. components: { UserIdToUsername, AddToPlaylistDropdown, SongThumbnail },
  166. props: {
  167. song: {
  168. type: Object,
  169. default: () => {}
  170. },
  171. requestedBy: {
  172. type: Boolean,
  173. default: false
  174. },
  175. duration: {
  176. type: Boolean,
  177. default: true
  178. },
  179. thumbnail: {
  180. type: Boolean,
  181. default: true
  182. },
  183. disabledActions: {
  184. type: Array,
  185. default: () => []
  186. },
  187. header: {
  188. type: String,
  189. default: null
  190. }
  191. },
  192. data() {
  193. return {
  194. utils,
  195. formatedRequestedAt: null,
  196. formatRequestedAtInterval: null,
  197. hoveredTippy: false
  198. };
  199. },
  200. computed: {
  201. ...mapState({
  202. loggedIn: state => state.user.auth.loggedIn,
  203. userRole: state => state.user.auth.role
  204. })
  205. },
  206. mounted() {
  207. if (this.requestedBy) {
  208. this.formatRequestedAt();
  209. this.formatRequestedAtInterval = setInterval(() => {
  210. this.formatRequestedAt();
  211. }, 30000);
  212. }
  213. },
  214. unmounted() {
  215. clearInterval(this.formatRequestedAtInterval);
  216. },
  217. methods: {
  218. formatRequestedAt() {
  219. if (this.requestedBy && this.song.requestedAt)
  220. this.formatedRequestedAt = this.formatDistance(
  221. parseISO(this.song.requestedAt),
  222. new Date()
  223. );
  224. },
  225. formatArtists() {
  226. if (this.song.artists.length === 1) {
  227. return this.song.artists[0];
  228. }
  229. if (this.song.artists.length === 2) {
  230. return this.song.artists.join(" & ");
  231. }
  232. if (this.song.artists.length > 2) {
  233. return `${this.song.artists
  234. .slice(0, -1)
  235. .join(", ")} & ${this.song.artists.slice(-1)}`;
  236. }
  237. return null;
  238. },
  239. hideTippyElements() {
  240. this.$refs.songActions.tippy.hide();
  241. setTimeout(
  242. () =>
  243. Array.from(
  244. document.querySelectorAll(".tippy-popper")
  245. ).forEach(popper => popper._tippy.hide()),
  246. 500
  247. );
  248. },
  249. hoverTippy() {
  250. this.hoveredTippy = true;
  251. },
  252. report(song) {
  253. this.hideTippyElements();
  254. this.reportSong(song);
  255. this.openModal("report");
  256. },
  257. edit(song) {
  258. this.hideTippyElements();
  259. this.editSong({ songId: song._id });
  260. this.openModal("editSong");
  261. },
  262. ...mapActions("modals/editSong", ["editSong"]),
  263. ...mapActions("modals/report", ["reportSong"]),
  264. ...mapActions("modalVisibility", ["openModal"]),
  265. formatDistance,
  266. parseISO
  267. }
  268. };
  269. </script>
  270. <style lang="less" scoped>
  271. .night-mode {
  272. .song-item {
  273. background-color: var(--dark-grey-2) !important;
  274. border: 0 !important;
  275. }
  276. }
  277. :deep(#nav-dropdown) {
  278. margin-top: 36px;
  279. width: 0;
  280. height: 0;
  281. .nav-dropdown-items {
  282. width: 250px;
  283. max-width: 100vw;
  284. position: relative;
  285. right: 175px;
  286. }
  287. }
  288. .song-item {
  289. min-height: 70px;
  290. &:not(:last-of-type) {
  291. margin-bottom: 10px;
  292. }
  293. .thumbnail-and-info,
  294. .duration-and-actions {
  295. display: flex;
  296. align-items: center;
  297. }
  298. .duration-and-actions {
  299. margin-left: 5px;
  300. .universal-item-actions div i {
  301. margin-left: 5px;
  302. }
  303. }
  304. .thumbnail-and-info {
  305. min-width: 0;
  306. }
  307. .thumbnail {
  308. min-width: 70px;
  309. width: 70px;
  310. height: 70px;
  311. margin: -7.5px;
  312. margin-right: calc(20px - 7.5px);
  313. }
  314. .song-info {
  315. display: flex;
  316. flex-direction: column;
  317. justify-content: center;
  318. // margin-left: 20px;
  319. min-width: 0;
  320. *:not(i) {
  321. margin: 0;
  322. font-family: Karla, Arial, sans-serif;
  323. }
  324. h6 {
  325. color: var(--primary-color) !important;
  326. font-weight: bold;
  327. font-size: 17px;
  328. margin-bottom: 5px;
  329. }
  330. .song-title {
  331. display: flex;
  332. flex-direction: row;
  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. .song-request-time {
  345. font-size: 12px;
  346. }
  347. }
  348. .song-duration {
  349. font-size: 20px;
  350. }
  351. .edit-icon {
  352. color: var(--primary-color);
  353. }
  354. }
  355. </style>