History.vue 4.3 KB

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