SongItem.vue 6.2 KB

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