Preferences.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref, onMounted } from "vue";
  3. import Toast from "toasters";
  4. import { storeToRefs } from "pinia";
  5. import { useWebsocketsStore } from "@/stores/websockets";
  6. import { useUserPreferencesStore } from "@/stores/userPreferences";
  7. const SaveButton = defineAsyncComponent(
  8. () => import("@/components/SaveButton.vue")
  9. );
  10. const { socket } = useWebsocketsStore();
  11. const userPreferencesStore = useUserPreferencesStore();
  12. const saveButton = ref();
  13. const localNightmode = ref(false);
  14. const localAutoSkipDisliked = ref(false);
  15. const localActivityLogPublic = ref(false);
  16. const localAnonymousSongRequests = ref(false);
  17. const localActivityWatch = ref(false);
  18. const {
  19. nightmode,
  20. autoSkipDisliked,
  21. activityLogPublic,
  22. anonymousSongRequests,
  23. activityWatch
  24. } = storeToRefs(userPreferencesStore);
  25. const saveChanges = () => {
  26. if (
  27. localNightmode.value === nightmode.value &&
  28. localAutoSkipDisliked.value === autoSkipDisliked.value &&
  29. localActivityLogPublic.value === activityLogPublic.value &&
  30. localAnonymousSongRequests.value === anonymousSongRequests.value &&
  31. localActivityWatch.value === activityWatch.value
  32. ) {
  33. new Toast("Please make a change before saving.");
  34. return saveButton.value.handleFailedSave();
  35. }
  36. saveButton.value.status = "disabled";
  37. return socket.dispatch(
  38. "users.updatePreferences",
  39. {
  40. nightmode: localNightmode.value,
  41. autoSkipDisliked: localAutoSkipDisliked.value,
  42. activityLogPublic: localActivityLogPublic.value,
  43. anonymousSongRequests: localAnonymousSongRequests.value,
  44. activityWatch: localActivityWatch.value
  45. },
  46. res => {
  47. if (res.status !== "success") {
  48. new Toast(res.message);
  49. return saveButton.value.handleFailedSave();
  50. }
  51. new Toast("Successfully updated preferences");
  52. return saveButton.value.handleSuccessfulSave();
  53. }
  54. );
  55. };
  56. onMounted(() => {
  57. socket.onConnect(() => {
  58. socket.dispatch("users.getPreferences", res => {
  59. const { preferences } = res.data;
  60. if (res.status === "success") {
  61. localNightmode.value = preferences.nightmode;
  62. localAutoSkipDisliked.value = preferences.autoSkipDisliked;
  63. localActivityLogPublic.value = preferences.activityLogPublic;
  64. localAnonymousSongRequests.value =
  65. preferences.anonymousSongRequests;
  66. localActivityWatch.value = preferences.activityWatch;
  67. }
  68. });
  69. });
  70. socket.on("keep.event:user.preferences.updated", res => {
  71. const { preferences } = res.data;
  72. if (preferences.nightmode !== undefined)
  73. localNightmode.value = preferences.nightmode;
  74. if (preferences.autoSkipDisliked !== undefined)
  75. localAutoSkipDisliked.value = preferences.autoSkipDisliked;
  76. if (preferences.activityLogPublic !== undefined)
  77. localActivityLogPublic.value = preferences.activityLogPublic;
  78. if (preferences.anonymousSongRequests !== undefined)
  79. localAnonymousSongRequests.value =
  80. preferences.anonymousSongRequests;
  81. if (preferences.activityWatch !== undefined)
  82. localActivityWatch.value = preferences.activityWatch;
  83. });
  84. });
  85. </script>
  86. <template>
  87. <div class="content preferences-tab">
  88. <h4 class="section-title">Change preferences</h4>
  89. <p class="section-description">Tailor these settings to your liking</p>
  90. <hr class="section-horizontal-rule" />
  91. <p class="control is-expanded checkbox-control">
  92. <label class="switch">
  93. <input
  94. type="checkbox"
  95. id="nightmode"
  96. v-model="localNightmode"
  97. />
  98. <span class="slider round"></span>
  99. </label>
  100. <label for="nightmode">
  101. <p>Use nightmode</p>
  102. </label>
  103. </p>
  104. <p class="control is-expanded checkbox-control">
  105. <label class="switch">
  106. <input
  107. type="checkbox"
  108. id="autoSkipDisliked"
  109. v-model="localAutoSkipDisliked"
  110. />
  111. <span class="slider round"></span>
  112. </label>
  113. <label for="autoSkipDisliked">
  114. <p>Automatically vote to skip disliked songs</p>
  115. </label>
  116. </p>
  117. <p class="control is-expanded checkbox-control">
  118. <label class="switch">
  119. <input
  120. type="checkbox"
  121. id="activityLogPublic"
  122. v-model="localActivityLogPublic"
  123. />
  124. <span class="slider round"></span>
  125. </label>
  126. <label for="activityLogPublic">
  127. <p>Allow my activity log to be viewed publicly</p>
  128. </label>
  129. </p>
  130. <p class="control is-expanded checkbox-control">
  131. <label class="switch">
  132. <input
  133. type="checkbox"
  134. id="anonymousSongRequests"
  135. v-model="localAnonymousSongRequests"
  136. />
  137. <span class="slider round"></span>
  138. </label>
  139. <label for="anonymousSongRequests">
  140. <span></span>
  141. <p>Request songs anonymously</p>
  142. </label>
  143. </p>
  144. <p class="control is-expanded checkbox-control">
  145. <label class="switch">
  146. <input
  147. type="checkbox"
  148. id="activityWatch"
  149. v-model="localActivityWatch"
  150. />
  151. <span class="slider round"></span>
  152. </label>
  153. <label for="activityWatch">
  154. <span></span>
  155. <p>Use ActivityWatch integration (requires extension)</p>
  156. </label>
  157. </p>
  158. <SaveButton ref="saveButton" @clicked="saveChanges()" />
  159. </div>
  160. </template>