SongItem.vue 7.8 KB

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