SongItem.vue 6.0 KB

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