SongItem.vue 8.8 KB

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