SongItem.vue 6.5 KB

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