SongItem.vue 7.8 KB

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