SongItem.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="universal-item song-item">
  3. <div class="thumbnail-and-info">
  4. <song-thumbnail :class="{ large: largeThumbnail }" :song="song" />
  5. <div class="song-info">
  6. <h6 v-if="header">{{ header }}</h6>
  7. <h4
  8. class="item-title"
  9. :style="
  10. song.artists && song.artists.length < 1
  11. ? { fontSize: '16px' }
  12. : null
  13. "
  14. :title="song.title"
  15. >
  16. {{ song.title }}
  17. <i
  18. v-if="song.status === 'verified'"
  19. class="material-icons verified-song"
  20. content="Verified Song"
  21. v-tippy
  22. >
  23. check_circle
  24. </i>
  25. </h4>
  26. <h5
  27. class="item-description"
  28. v-if="song.artists"
  29. :title="song.artists.join(', ')"
  30. >
  31. {{ song.artists.join(", ") }}
  32. </h5>
  33. <p
  34. class="song-request-time"
  35. v-if="requestedBy && song.requestedBy"
  36. >
  37. Requested by
  38. <strong>
  39. <user-id-to-username
  40. :user-id="song.requestedBy"
  41. :link="true"
  42. />
  43. {{
  44. formatDistance(
  45. parseISO(song.requestedAt),
  46. new Date(),
  47. {
  48. includeSeconds: true
  49. }
  50. )
  51. }}
  52. ago
  53. </strong>
  54. </p>
  55. </div>
  56. </div>
  57. <div class="duration-and-actions">
  58. <p v-if="duration" class="song-duration">
  59. {{ utils.formatTime(song.duration) }}
  60. </p>
  61. <div class="universal-item-actions">
  62. <tippy
  63. v-if="loggedIn"
  64. interactive="true"
  65. placement="left"
  66. theme="songActions"
  67. ref="songActions"
  68. trigger="click"
  69. >
  70. <template #trigger>
  71. <i
  72. class="material-icons action-dropdown-icon"
  73. content="Song Options"
  74. v-tippy
  75. >more_horiz</i
  76. >
  77. </template>
  78. <a
  79. target="_blank"
  80. :href="`https://www.youtube.com/watch?v=${song.songId}`"
  81. content="View on Youtube"
  82. v-tippy
  83. >
  84. <div class="youtube-icon"></div>
  85. </a>
  86. <i
  87. class="material-icons report-icon"
  88. @click="report(song)"
  89. content="Report Song"
  90. v-tippy
  91. >
  92. flag
  93. </i>
  94. <add-to-playlist-dropdown :song="song">
  95. <i
  96. slot="button"
  97. class="material-icons add-to-playlist-icon"
  98. content="Add Song to Playlist"
  99. v-tippy
  100. >playlist_add</i
  101. >
  102. </add-to-playlist-dropdown>
  103. <i
  104. v-if="loggedIn && userRole === 'admin'"
  105. class="material-icons edit-icon"
  106. @click="edit(song)"
  107. content="Edit Song"
  108. v-tippy
  109. >
  110. edit
  111. </i>
  112. <slot name="actions" />
  113. </tippy>
  114. <a
  115. v-else
  116. target="_blank"
  117. :href="`https://www.youtube.com/watch?v=${song.songId}`"
  118. content="View on Youtube"
  119. v-tippy
  120. >
  121. <div class="youtube-icon"></div>
  122. </a>
  123. </div>
  124. </div>
  125. </div>
  126. </template>
  127. <script>
  128. import { mapActions, mapState } from "vuex";
  129. import { formatDistance, parseISO } from "date-fns";
  130. import AddToPlaylistDropdown from "./AddToPlaylistDropdown.vue";
  131. import UserIdToUsername from "./UserIdToUsername.vue";
  132. import SongThumbnail from "./SongThumbnail.vue";
  133. import utils from "../../js/utils";
  134. export default {
  135. components: { UserIdToUsername, AddToPlaylistDropdown, SongThumbnail },
  136. props: {
  137. song: {
  138. type: Object,
  139. default: () => {}
  140. },
  141. requestedBy: {
  142. type: Boolean,
  143. default: false
  144. },
  145. duration: {
  146. type: Boolean,
  147. default: true
  148. },
  149. largeThumbnail: {
  150. type: Boolean,
  151. default: false
  152. },
  153. header: {
  154. type: String,
  155. default: null
  156. }
  157. },
  158. data() {
  159. return {
  160. utils
  161. };
  162. },
  163. computed: {
  164. ...mapState({
  165. loggedIn: state => state.user.auth.loggedIn,
  166. userRole: state => state.user.auth.role
  167. })
  168. },
  169. methods: {
  170. hideTippyElements() {
  171. this.$refs.songActions.tip.hide();
  172. setTimeout(
  173. () =>
  174. Array.from(
  175. document.querySelectorAll(".tippy-popper")
  176. ).forEach(popper => popper._tippy.hide()),
  177. 500
  178. );
  179. },
  180. report(song) {
  181. this.hideTippyElements();
  182. this.reportSong(song);
  183. this.openModal({ sector: "station", modal: "report" });
  184. },
  185. edit(song) {
  186. this.hideTippyElements();
  187. this.editSong(song);
  188. this.openModal({ sector: "admin", modal: "editSong" });
  189. },
  190. ...mapActions("modals/editSong", ["editSong"]),
  191. ...mapActions("modals/report", ["reportSong"]),
  192. ...mapActions("modalVisibility", ["openModal"]),
  193. formatDistance,
  194. parseISO
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .night-mode {
  200. .song-item {
  201. background-color: var(--dark-grey-2) !important;
  202. border: 0 !important;
  203. }
  204. }
  205. /deep/ #nav-dropdown {
  206. margin-top: 36px;
  207. width: 0;
  208. height: 0;
  209. .nav-dropdown-items {
  210. width: 250px;
  211. max-width: 100vw;
  212. position: relative;
  213. right: 175px;
  214. }
  215. }
  216. .song-item {
  217. .thumbnail-and-info,
  218. .duration-and-actions {
  219. display: flex;
  220. align-items: center;
  221. }
  222. .duration-and-actions {
  223. margin-left: 5px;
  224. .universal-item-actions div i {
  225. margin-left: 5px;
  226. }
  227. }
  228. .thumbnail-and-info {
  229. width: calc(100% - 90px);
  230. }
  231. .thumbnail {
  232. min-width: 65px;
  233. width: 65px;
  234. height: 65px;
  235. margin: -7.5px;
  236. &.large {
  237. min-width: 130px;
  238. width: 130px;
  239. height: 130px;
  240. }
  241. }
  242. .song-info {
  243. display: flex;
  244. flex-direction: column;
  245. justify-content: center;
  246. margin-left: 20px;
  247. width: calc(100% - 80px);
  248. *:not(i) {
  249. margin: 0;
  250. font-family: Karla, Arial, sans-serif;
  251. }
  252. h6 {
  253. color: var(--primary-color) !important;
  254. font-weight: bold;
  255. font-size: 17px;
  256. margin-bottom: 5px;
  257. }
  258. .song-request-time {
  259. font-size: 12px;
  260. margin-top: 7px;
  261. }
  262. }
  263. .song-duration {
  264. font-size: 20px;
  265. }
  266. .edit-icon {
  267. color: var(--primary-color);
  268. }
  269. }
  270. </style>