Preferences.vue 5.2 KB

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