SongItem.vue 7.6 KB

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