SongItem.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <script setup lang="ts">
  2. import { useStore } from "vuex";
  3. import { ref, computed, onMounted, onUnmounted } from "vue";
  4. import { formatDistance, parseISO } from "date-fns";
  5. import AddToPlaylistDropdown from "./AddToPlaylistDropdown.vue";
  6. import utils from "@/utils";
  7. const store = useStore();
  8. const props = defineProps({
  9. song: {
  10. type: Object,
  11. default: () => {}
  12. },
  13. requestedBy: {
  14. type: Boolean,
  15. default: false
  16. },
  17. duration: {
  18. type: Boolean,
  19. default: true
  20. },
  21. thumbnail: {
  22. type: Boolean,
  23. default: true
  24. },
  25. disabledActions: {
  26. type: Array,
  27. default: () => []
  28. },
  29. header: {
  30. type: String,
  31. default: null
  32. }
  33. });
  34. const formatedRequestedAt = ref(null);
  35. const formatRequestedAtInterval = ref();
  36. const hoveredTippy = ref(false);
  37. const songActions = ref(null);
  38. const loggedIn = computed(() => store.state.user.auth.loggedIn);
  39. const userRole = computed(() => store.state.user.auth.role);
  40. function formatRequestedAt() {
  41. if (props.requestedBy && props.song.requestedAt)
  42. formatedRequestedAt.value = formatDistance(
  43. parseISO(props.song.requestedAt),
  44. new Date()
  45. );
  46. }
  47. function formatArtists() {
  48. if (props.song.artists.length === 1) {
  49. return props.song.artists[0];
  50. }
  51. if (props.song.artists.length === 2) {
  52. return props.song.artists.join(" & ");
  53. }
  54. if (props.song.artists.length > 2) {
  55. return `${props.song.artists
  56. .slice(0, -1)
  57. .join(", ")} & ${props.song.artists.slice(-1)}`;
  58. }
  59. return null;
  60. }
  61. function hideTippyElements() {
  62. songActions.value.tippy.hide();
  63. setTimeout(
  64. () =>
  65. Array.from(document.querySelectorAll(".tippy-popper")).forEach(
  66. popper => popper._tippy.hide()
  67. ),
  68. 500
  69. );
  70. }
  71. function hoverTippy() {
  72. hoveredTippy.value = true;
  73. }
  74. function openModal(payload) {
  75. store.dispatch("modalVisibility/openModal", payload);
  76. }
  77. function report(song) {
  78. hideTippyElements();
  79. openModal({ modal: "report", data: { song } });
  80. }
  81. function edit(song) {
  82. hideTippyElements();
  83. openModal({
  84. modal: "editSong",
  85. data: { song }
  86. });
  87. }
  88. onMounted(() => {
  89. if (props.requestedBy) {
  90. formatRequestedAt();
  91. formatRequestedAtInterval.value = setInterval(() => {
  92. formatRequestedAt();
  93. }, 30000);
  94. }
  95. });
  96. onUnmounted(() => {
  97. clearInterval(formatRequestedAtInterval.value);
  98. });
  99. </script>
  100. <template>
  101. <div
  102. class="universal-item song-item"
  103. :class="{ 'with-duration': duration }"
  104. v-if="song"
  105. >
  106. <div class="thumbnail-and-info">
  107. <slot v-if="$slots.leftIcon" name="leftIcon" />
  108. <song-thumbnail :song="song" v-if="thumbnail" />
  109. <div class="song-info">
  110. <h6 v-if="header">{{ header }}</h6>
  111. <div class="song-title">
  112. <h4
  113. :class="{
  114. 'item-title': true,
  115. 'no-artists':
  116. !song.artists ||
  117. (song.artists && song.artists.length < 1)
  118. }"
  119. :title="song.title"
  120. >
  121. {{ song.title }}
  122. </h4>
  123. <i
  124. v-if="song.verified"
  125. class="material-icons verified-song"
  126. content="Verified Song"
  127. v-tippy="{ theme: 'info' }"
  128. >
  129. check_circle
  130. </i>
  131. </div>
  132. <h5
  133. class="item-description"
  134. v-if="formatArtists()"
  135. :title="formatArtists()"
  136. >
  137. {{ formatArtists() }}
  138. </h5>
  139. <p class="song-request-time" v-if="requestedBy">
  140. Requested by
  141. <strong>
  142. <user-link
  143. v-if="song.requestedBy"
  144. :key="song._id"
  145. :user-id="song.requestedBy"
  146. />
  147. <span v-else>station</span>
  148. {{ formatedRequestedAt }}
  149. ago
  150. </strong>
  151. </p>
  152. </div>
  153. </div>
  154. <div class="duration-and-actions">
  155. <p v-if="duration" class="song-duration">
  156. {{ utils.formatTime(song.duration) }}
  157. </p>
  158. <div
  159. class="universal-item-actions"
  160. v-if="disabledActions.indexOf('all') === -1"
  161. >
  162. <tippy
  163. v-if="loggedIn && hoveredTippy"
  164. :touch="true"
  165. :interactive="true"
  166. placement="left"
  167. theme="songActions"
  168. ref="songActions"
  169. trigger="click"
  170. >
  171. <i
  172. class="material-icons action-dropdown-icon"
  173. content="Song Options"
  174. v-tippy
  175. >more_horiz</i
  176. >
  177. <template #content>
  178. <div class="icons-group">
  179. <i
  180. v-if="disabledActions.indexOf('youtube') === -1"
  181. @click="
  182. openModal({
  183. modal: 'viewYoutubeVideo',
  184. data: {
  185. youtubeId: song.youtubeId
  186. }
  187. })
  188. "
  189. content="View YouTube Video"
  190. v-tippy
  191. >
  192. <div class="youtube-icon"></div>
  193. </i>
  194. <i
  195. v-if="
  196. song._id &&
  197. disabledActions.indexOf('report') === -1
  198. "
  199. class="material-icons report-icon"
  200. @click="report(song)"
  201. content="Report Song"
  202. v-tippy
  203. >
  204. flag
  205. </i>
  206. <add-to-playlist-dropdown
  207. v-if="
  208. disabledActions.indexOf('addToPlaylist') ===
  209. -1
  210. "
  211. :song="song"
  212. placement="top-end"
  213. >
  214. <template #button>
  215. <i
  216. class="material-icons add-to-playlist-icon"
  217. content="Add Song to Playlist"
  218. v-tippy
  219. >playlist_add</i
  220. >
  221. </template>
  222. </add-to-playlist-dropdown>
  223. <i
  224. v-if="
  225. loggedIn &&
  226. song._id &&
  227. userRole === 'admin' &&
  228. disabledActions.indexOf('edit') === -1
  229. "
  230. class="material-icons edit-icon"
  231. @click="edit(song)"
  232. content="Edit Song"
  233. v-tippy
  234. >
  235. edit
  236. </i>
  237. <slot name="tippyActions" />
  238. </div>
  239. </template>
  240. </tippy>
  241. <i
  242. class="material-icons action-dropdown-icon"
  243. v-else-if="loggedIn && !hoveredTippy"
  244. @mouseenter="hoverTippy()"
  245. >more_horiz</i
  246. >
  247. <a
  248. v-else-if="
  249. !loggedIn && disabledActions.indexOf('youtube') === -1
  250. "
  251. target="_blank"
  252. :href="`https://www.youtube.com/watch?v=${song.youtubeId}`"
  253. content="View on Youtube"
  254. v-tippy
  255. >
  256. <div class="youtube-icon"></div>
  257. </a>
  258. </div>
  259. <div class="universal-item-actions" v-if="$slots.actions">
  260. <slot name="actions" />
  261. </div>
  262. </div>
  263. </div>
  264. </template>
  265. <style lang="less" scoped>
  266. .night-mode {
  267. .song-item {
  268. background-color: var(--dark-grey-2) !important;
  269. border: 0 !important;
  270. }
  271. }
  272. :deep(#nav-dropdown) {
  273. margin-top: 36px;
  274. width: 0;
  275. height: 0;
  276. .nav-dropdown-items {
  277. width: 250px;
  278. max-width: 100vw;
  279. position: relative;
  280. right: 175px;
  281. }
  282. }
  283. .song-item {
  284. min-height: 70px;
  285. &:not(:last-of-type) {
  286. margin-bottom: 10px;
  287. }
  288. .thumbnail-and-info,
  289. .duration-and-actions {
  290. display: flex;
  291. align-items: center;
  292. }
  293. .duration-and-actions {
  294. margin-left: 5px;
  295. .universal-item-actions div i {
  296. margin-left: 5px;
  297. }
  298. }
  299. .thumbnail-and-info {
  300. min-width: 0;
  301. }
  302. .thumbnail {
  303. min-width: 70px;
  304. width: 70px;
  305. height: 70px;
  306. margin: -7.5px;
  307. margin-right: calc(20px - 7.5px);
  308. }
  309. .song-info {
  310. display: flex;
  311. flex-direction: column;
  312. justify-content: center;
  313. // margin-left: 20px;
  314. min-width: 0;
  315. *:not(i) {
  316. margin: 0;
  317. font-family: Karla, Arial, sans-serif;
  318. }
  319. h6 {
  320. color: var(--primary-color) !important;
  321. font-weight: bold;
  322. font-size: 17px;
  323. margin-bottom: 5px;
  324. }
  325. .song-title {
  326. display: flex;
  327. flex-direction: row;
  328. .item-title {
  329. font-size: 18px;
  330. }
  331. .verified-song {
  332. margin-left: 5px;
  333. }
  334. .item-title.no-artists {
  335. display: -webkit-inline-box;
  336. font-size: 16px;
  337. white-space: normal;
  338. -webkit-box-orient: vertical;
  339. -webkit-line-clamp: 2;
  340. }
  341. }
  342. .item-description {
  343. line-height: 120%;
  344. }
  345. .song-request-time {
  346. font-size: 11px;
  347. overflow: hidden;
  348. text-overflow: ellipsis;
  349. white-space: nowrap;
  350. }
  351. }
  352. .song-duration {
  353. font-size: 20px;
  354. }
  355. .edit-icon {
  356. color: var(--primary-color);
  357. }
  358. }
  359. </style>