SongItem.vue 6.7 KB

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