History.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, computed, onMounted } from "vue";
  3. import Toast from "toasters";
  4. import { storeToRefs } from "pinia";
  5. import { useWebsocketsStore } from "@/stores/websockets";
  6. import { useStationStore } from "@/stores/station";
  7. import SongItem from "@/components/SongItem.vue";
  8. const stationStore = useStationStore();
  9. const { socket } = useWebsocketsStore();
  10. const { history } = storeToRefs(stationStore);
  11. const station = computed({
  12. get() {
  13. return stationStore.station;
  14. },
  15. set(value) {
  16. stationStore.updateStation(value);
  17. }
  18. });
  19. const songsList = computed({
  20. get() {
  21. return stationStore.songsList;
  22. },
  23. set(value) {
  24. stationStore.updateSongsList(value);
  25. }
  26. });
  27. const songsInQueue = computed(() => {
  28. if (station.value.currentSong)
  29. return songsList.value
  30. .map(song => song.youtubeId)
  31. .concat(station.value.currentSong.youtubeId);
  32. return songsList.value.map(song => song.youtubeId);
  33. });
  34. const formatDate = dateString => {
  35. const skippedAtDate = new Date(dateString);
  36. const now = new Date();
  37. const time = `${skippedAtDate
  38. .getHours()
  39. .toString()
  40. .padStart(2, "0")}:${skippedAtDate
  41. .getMinutes()
  42. .toString()
  43. .padStart(2, "0")}`;
  44. const date = `${skippedAtDate.getFullYear()}-${(
  45. skippedAtDate.getMonth() + 1
  46. )
  47. .toString()
  48. .padStart(2, "0")}-${skippedAtDate
  49. .getDate()
  50. .toString()
  51. .padStart(2, "0")}`;
  52. if (skippedAtDate.toLocaleDateString() === now.toLocaleDateString()) {
  53. return time;
  54. }
  55. return `${date} ${time}`;
  56. };
  57. const formatSkipReason = skipReason => {
  58. if (skipReason === "natural") return "";
  59. if (skipReason === "other") return " - automatically skipped";
  60. if (skipReason === "vote_skip") return " - vote skipped";
  61. if (skipReason === "force_skip") return " - force skipped";
  62. return "";
  63. };
  64. const addSongToQueue = (youtubeId: string) => {
  65. socket.dispatch(
  66. "stations.addToQueue",
  67. station.value._id,
  68. youtubeId,
  69. res => {
  70. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  71. else {
  72. new Toast(res.message);
  73. }
  74. }
  75. );
  76. };
  77. onMounted(async () => {});
  78. </script>
  79. <template>
  80. <div class="station-history">
  81. <div v-for="historyItem in history" :key="historyItem._id">
  82. <SongItem
  83. :song="historyItem.payload.song"
  84. :requested-by="true"
  85. :header="`Finished playing at ${formatDate(
  86. historyItem.payload.skippedAt
  87. )}${formatSkipReason(historyItem.payload.skipReason)}`"
  88. >
  89. <template #actions>
  90. <transition
  91. name="musare-history-query-actions"
  92. mode="out-in"
  93. >
  94. <i
  95. v-if="
  96. songsInQueue.indexOf(
  97. historyItem.payload.song.youtubeId
  98. ) !== -1
  99. "
  100. class="material-icons disabled"
  101. content="Song is already in queue"
  102. v-tippy
  103. >queue</i
  104. >
  105. <i
  106. v-else
  107. class="material-icons add-to-queue-icon"
  108. @click="
  109. addSongToQueue(
  110. historyItem.payload.song.youtubeId
  111. )
  112. "
  113. content="Add Song to Queue"
  114. v-tippy
  115. >queue</i
  116. >
  117. </transition>
  118. </template>
  119. </SongItem>
  120. </div>
  121. </div>
  122. </template>
  123. <style lang="less" scoped>
  124. .night-mode {
  125. .station-history {
  126. background-color: var(--dark-grey-3) !important;
  127. border: 0 !important;
  128. }
  129. }
  130. .station-history {
  131. background-color: var(--white);
  132. margin-bottom: 20px;
  133. border-radius: 0 0 @border-radius @border-radius;
  134. max-height: 100%;
  135. padding: 12px;
  136. overflow: auto;
  137. row-gap: 8px;
  138. display: flex;
  139. flex-direction: column;
  140. h1 {
  141. margin: 0;
  142. }
  143. .disabled {
  144. cursor: not-allowed;
  145. }
  146. :deep(.song-item) {
  147. height: 90px;
  148. .thumbnail {
  149. min-width: 90px;
  150. width: 90px;
  151. height: 90px;
  152. }
  153. .song-info {
  154. margin-left: 90px;
  155. }
  156. }
  157. }
  158. </style>