SongItem.vue 7.8 KB

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