SongItem.vue 7.4 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. <song-thumbnail :song="song" v-if="thumbnail" />
  9. <div class="song-info">
  10. <h6 v-if="header">{{ header }}</h6>
  11. <div class="song-title">
  12. <h4
  13. class="item-title"
  14. :style="
  15. song.artists && song.artists.length < 1
  16. ? { fontSize: '16px' }
  17. : null
  18. "
  19. :title="song.title"
  20. >
  21. {{ song.title }}
  22. </h4>
  23. <i
  24. v-if="song.verified"
  25. class="material-icons verified-song"
  26. content="Verified Song"
  27. v-tippy="{ theme: 'info' }"
  28. >
  29. check_circle
  30. </i>
  31. </div>
  32. <h5
  33. class="item-description"
  34. v-if="formatArtists()"
  35. :title="formatArtists()"
  36. >
  37. {{ formatArtists() }}
  38. </h5>
  39. <p
  40. class="song-request-time"
  41. v-if="requestedBy && song.requestedBy"
  42. >
  43. Requested by
  44. <strong>
  45. <user-id-to-username
  46. :key="song._id"
  47. :user-id="song.requestedBy"
  48. :link="true"
  49. />
  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="
  110. material-icons
  111. add-to-playlist-icon
  112. "
  113. content="Add Song to Playlist"
  114. v-tippy
  115. >playlist_add</i
  116. >
  117. </template>
  118. </add-to-playlist-dropdown>
  119. <i
  120. v-if="
  121. loggedIn &&
  122. userRole === 'admin' &&
  123. disabledActions.indexOf('edit') === -1
  124. "
  125. class="material-icons edit-icon"
  126. @click="edit(song)"
  127. content="Edit Song"
  128. v-tippy
  129. >
  130. edit
  131. </i>
  132. <slot name="tippyActions" />
  133. </div>
  134. </template>
  135. </tippy>
  136. <i
  137. class="material-icons action-dropdown-icon"
  138. v-else-if="loggedIn && !hoveredTippy"
  139. @mouseenter="hoverTippy()"
  140. >more_horiz</i
  141. >
  142. <a
  143. v-else-if="
  144. !loggedIn && disabledActions.indexOf('youtube') === -1
  145. "
  146. target="_blank"
  147. :href="`https://www.youtube.com/watch?v=${song.youtubeId}`"
  148. content="View on Youtube"
  149. v-tippy
  150. >
  151. <div class="youtube-icon"></div>
  152. </a>
  153. </div>
  154. <div class="universal-item-actions" v-if="$slots.actions">
  155. <slot name="actions" />
  156. </div>
  157. </div>
  158. </div>
  159. </template>
  160. <script>
  161. import { mapActions, mapState } from "vuex";
  162. import { formatDistance, parseISO } from "date-fns";
  163. import AddToPlaylistDropdown from "./AddToPlaylistDropdown.vue";
  164. import UserIdToUsername from "./UserIdToUsername.vue";
  165. import SongThumbnail from "./SongThumbnail.vue";
  166. import utils from "../../js/utils";
  167. export default {
  168. components: { UserIdToUsername, AddToPlaylistDropdown, SongThumbnail },
  169. props: {
  170. song: {
  171. type: Object,
  172. default: () => {}
  173. },
  174. requestedBy: {
  175. type: Boolean,
  176. default: false
  177. },
  178. duration: {
  179. type: Boolean,
  180. default: true
  181. },
  182. thumbnail: {
  183. type: Boolean,
  184. default: true
  185. },
  186. disabledActions: {
  187. type: Array,
  188. default: () => []
  189. },
  190. header: {
  191. type: String,
  192. default: null
  193. }
  194. },
  195. data() {
  196. return {
  197. utils,
  198. formatedRequestedAt: null,
  199. formatRequestedAtInterval: null,
  200. hoveredTippy: false
  201. };
  202. },
  203. computed: {
  204. ...mapState({
  205. loggedIn: state => state.user.auth.loggedIn,
  206. userRole: state => state.user.auth.role
  207. })
  208. },
  209. mounted() {
  210. if (this.requestedBy) {
  211. this.formatRequestedAt();
  212. this.formatRequestedAtInterval = setInterval(() => {
  213. this.formatRequestedAt();
  214. }, 30000);
  215. }
  216. },
  217. unmounted() {
  218. clearInterval(this.formatRequestedAtInterval);
  219. },
  220. methods: {
  221. formatRequestedAt() {
  222. if (
  223. this.requestedBy &&
  224. this.song.requestedBy &&
  225. this.song.requestedAt
  226. )
  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.reportSong(song);
  262. this.openModal("report");
  263. },
  264. edit(song) {
  265. this.hideTippyElements();
  266. this.editSong(song);
  267. this.openModal("editSong");
  268. },
  269. ...mapActions("modals/editSong", ["editSong"]),
  270. ...mapActions("modals/report", ["reportSong"]),
  271. ...mapActions("modalVisibility", ["openModal"]),
  272. formatDistance,
  273. parseISO
  274. }
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. .night-mode {
  279. .song-item {
  280. background-color: var(--dark-grey-2) !important;
  281. border: 0 !important;
  282. }
  283. }
  284. /deep/ #nav-dropdown {
  285. margin-top: 36px;
  286. width: 0;
  287. height: 0;
  288. .nav-dropdown-items {
  289. width: 250px;
  290. max-width: 100vw;
  291. position: relative;
  292. right: 175px;
  293. }
  294. }
  295. .song-item {
  296. min-height: 65px;
  297. &:not(:last-of-type) {
  298. margin-bottom: 10px;
  299. }
  300. .thumbnail-and-info,
  301. .duration-and-actions {
  302. display: flex;
  303. align-items: center;
  304. }
  305. .duration-and-actions {
  306. margin-left: 5px;
  307. .universal-item-actions div i {
  308. margin-left: 5px;
  309. }
  310. }
  311. .thumbnail-and-info {
  312. min-width: 0;
  313. }
  314. .thumbnail {
  315. min-width: 65px;
  316. width: 65px;
  317. height: 65px;
  318. margin: -7.5px;
  319. margin-right: calc(20px - 7.5px);
  320. }
  321. .song-info {
  322. display: flex;
  323. flex-direction: column;
  324. justify-content: center;
  325. // margin-left: 20px;
  326. min-width: 0;
  327. *:not(i) {
  328. margin: 0;
  329. font-family: Karla, Arial, sans-serif;
  330. }
  331. h6 {
  332. color: var(--primary-color) !important;
  333. font-weight: bold;
  334. font-size: 17px;
  335. margin-bottom: 5px;
  336. }
  337. .song-title {
  338. display: flex;
  339. flex-direction: row;
  340. .verified-song {
  341. margin-left: 5px;
  342. }
  343. }
  344. .song-request-time {
  345. font-size: 12px;
  346. margin-top: 7px;
  347. }
  348. }
  349. .song-duration {
  350. font-size: 20px;
  351. }
  352. .edit-icon {
  353. color: var(--primary-color);
  354. }
  355. }
  356. </style>