SongItem.vue 7.1 KB

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