Preferences.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 SaveButton from "@/components/SaveButton.vue";
  80. export default {
  81. components: { SaveButton },
  82. data() {
  83. return {
  84. localNightmode: false,
  85. localAutoSkipDisliked: false,
  86. localActivityLogPublic: false,
  87. localAnonymousSongRequests: false,
  88. localActivityWatch: false
  89. };
  90. },
  91. computed: {
  92. ...mapState({
  93. nightmode: state => state.user.preferences.nightmode,
  94. autoSkipDisliked: state => state.user.preferences.autoSkipDisliked,
  95. activityLogPublic: state =>
  96. state.user.preferences.activityLogPublic,
  97. anonymousSongRequests: state =>
  98. state.user.preferences.anonymousSongRequests,
  99. activityWatch: state => state.user.preferences.activityWatch
  100. }),
  101. ...mapGetters({
  102. socket: "websockets/getSocket"
  103. })
  104. },
  105. mounted() {
  106. this.socket.dispatch("users.getPreferences", res => {
  107. const { preferences } = res.data;
  108. if (res.status === "success") {
  109. this.localNightmode = preferences.nightmode;
  110. this.localAutoSkipDisliked = preferences.autoSkipDisliked;
  111. this.localActivityLogPublic = preferences.activityLogPublic;
  112. this.localAnonymousSongRequests =
  113. preferences.anonymousSongRequests;
  114. this.localActivityWatch = preferences.activityWatch;
  115. }
  116. });
  117. this.socket.on("keep.event:user.preferences.updated", res => {
  118. const { preferences } = res.data;
  119. this.localNightmode = preferences.nightmode;
  120. this.localAutoSkipDisliked = preferences.autoSkipDisliked;
  121. this.localActivityLogPublic = preferences.activityLogPublic;
  122. this.localAnonymousSongRequests = preferences.anonymousSongRequests;
  123. this.localActivityWatch = preferences.activityWatch;
  124. });
  125. },
  126. methods: {
  127. saveChanges() {
  128. if (
  129. this.localNightmode === this.nightmode &&
  130. this.localAutoSkipDisliked === this.autoSkipDisliked &&
  131. this.localActivityLogPublic === this.activityLogPublic &&
  132. this.localAnonymousSongRequests ===
  133. this.anonymousSongRequests &&
  134. this.localActivityWatch === this.activityWatch
  135. ) {
  136. new Toast("Please make a change before saving.");
  137. return this.$refs.saveButton.handleFailedSave();
  138. }
  139. this.$refs.saveButton.status = "disabled";
  140. return this.socket.dispatch(
  141. "users.updatePreferences",
  142. {
  143. nightmode: this.localNightmode,
  144. autoSkipDisliked: this.localAutoSkipDisliked,
  145. activityLogPublic: this.localActivityLogPublic,
  146. anonymousSongRequests: this.localAnonymousSongRequests,
  147. activityWatch: this.localActivityWatch
  148. },
  149. res => {
  150. if (res.status !== "success") {
  151. new Toast(res.message);
  152. return this.$refs.saveButton.handleFailedSave();
  153. }
  154. new Toast("Successfully updated preferences");
  155. return this.$refs.saveButton.handleSuccessfulSave();
  156. }
  157. );
  158. },
  159. ...mapActions("user/preferences", [
  160. "changeNightmode",
  161. "changeAutoSkipDisliked",
  162. "changeActivityLogPublic",
  163. "changeAnonymousSongRequests",
  164. "changeActivityWatch"
  165. ])
  166. }
  167. };
  168. </script>