SongItem.vue 6.3 KB

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