SongItem.vue 6.3 KB

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