SongItem.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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.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. 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 (
  219. this.requestedBy &&
  220. this.song.requestedBy &&
  221. this.song.requestedAt
  222. )
  223. this.formatedRequestedAt = this.formatDistance(
  224. parseISO(this.song.requestedAt),
  225. new Date()
  226. );
  227. },
  228. formatArtists() {
  229. if (this.song.artists.length === 1) {
  230. return this.song.artists[0];
  231. }
  232. if (this.song.artists.length === 2) {
  233. return this.song.artists.join(" & ");
  234. }
  235. if (this.song.artists.length > 2) {
  236. return `${this.song.artists
  237. .slice(0, -1)
  238. .join(", ")} & ${this.song.artists.slice(-1)}`;
  239. }
  240. return null;
  241. },
  242. hideTippyElements() {
  243. this.$refs.songActions.tippy.hide();
  244. setTimeout(
  245. () =>
  246. Array.from(
  247. document.querySelectorAll(".tippy-popper")
  248. ).forEach(popper => popper._tippy.hide()),
  249. 500
  250. );
  251. },
  252. hoverTippy() {
  253. this.hoveredTippy = true;
  254. },
  255. report(song) {
  256. this.hideTippyElements();
  257. this.reportSong(song);
  258. this.openModal("report");
  259. },
  260. edit(song) {
  261. this.hideTippyElements();
  262. this.editSong(song);
  263. this.openModal("editSong");
  264. },
  265. ...mapActions("modals/editSong", ["editSong"]),
  266. ...mapActions("modals/report", ["reportSong"]),
  267. ...mapActions("modalVisibility", ["openModal"]),
  268. formatDistance,
  269. parseISO
  270. }
  271. };
  272. </script>
  273. <style lang="scss" scoped>
  274. .night-mode {
  275. .song-item {
  276. background-color: var(--dark-grey-2) !important;
  277. border: 0 !important;
  278. }
  279. }
  280. /deep/ #nav-dropdown {
  281. margin-top: 36px;
  282. width: 0;
  283. height: 0;
  284. .nav-dropdown-items {
  285. width: 250px;
  286. max-width: 100vw;
  287. position: relative;
  288. right: 175px;
  289. }
  290. }
  291. .song-item {
  292. &:not(:last-of-type) {
  293. margin-bottom: 10px;
  294. }
  295. .thumbnail-and-info,
  296. .duration-and-actions {
  297. display: flex;
  298. align-items: center;
  299. }
  300. .duration-and-actions {
  301. margin-left: 5px;
  302. .universal-item-actions div i {
  303. margin-left: 5px;
  304. }
  305. }
  306. .thumbnail-and-info {
  307. min-width: 0;
  308. }
  309. .thumbnail {
  310. min-width: 65px;
  311. width: 65px;
  312. height: 65px;
  313. margin: -7.5px;
  314. }
  315. .song-info {
  316. display: flex;
  317. flex-direction: column;
  318. justify-content: center;
  319. margin-left: 20px;
  320. min-width: 0;
  321. *:not(i) {
  322. margin: 0;
  323. font-family: Karla, Arial, sans-serif;
  324. }
  325. h6 {
  326. color: var(--primary-color) !important;
  327. font-weight: bold;
  328. font-size: 17px;
  329. margin-bottom: 5px;
  330. }
  331. .song-title {
  332. display: flex;
  333. flex-direction: row;
  334. .verified-song {
  335. margin-left: 5px;
  336. }
  337. }
  338. .song-request-time {
  339. font-size: 12px;
  340. margin-top: 7px;
  341. }
  342. }
  343. .song-duration {
  344. font-size: 20px;
  345. }
  346. .edit-icon {
  347. color: var(--primary-color);
  348. }
  349. }
  350. </style>